You are Here:
Linux Lite 4.6 RC1 has been released. See the Release Announcements section for more information.



Cron job to automate backup????

Author (Read 4381 times)

0 Members and 3 Guests are viewing this topic.

Cron job to automate backup????
« on: December 14, 2015, 01:09:11 AM »
 

kjacobs

  • Occasional Poster
  • **
  • 71
    Posts
  • Reputation: 5
  • Linux Lite Member

  • CPU: 2x Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz

  • MEMORY: 4Gb
OK.....so I am trying to automate a weekly backup of my home folder. I did try the built in backup option in LL, but simply do not like the tons of zip files created during backup. I really only want mirror copies of the home folder on my NAS.

I installed grsync to setup the backup......and the backup works fine. I then created a backup.sh file to run the grsync backup session, made it executable, and tested it......it works fine as well.

Now I tried to add the script to a crontab job......this is where it all fails. I cannot get the file to run at all. I have tried MANY options.....I have added the path to the script to crontab.....tried adding the path in the script.......tried copying the script to the /bin folder.......tried standing on one foot while patting my head. I simply cannot get the file to launch using crontab. I have spent a number of hours looking up the correct formatting on google to get this right and it still fails to run.

I also tried installing gnome-scheduler to do this in a gui and it fails to run as well. Soooooo, what in the world am I missing to get this function to run automagically????

Any help would be great......thanks.

 


Re: Cron job to automate backup????
« Reply #1 on: December 14, 2015, 08:07:28 AM »
 

firenice03

  • Rockin' the FREE World
  • Platinum Level Poster
  • **********
  • 1105
    Posts
  • Country: us
  • Reputation: 220
  • Linux Lite Member

  • Linux Lite: 4.4 64bit

  • CPU: AMD E2//Atom X5//AMD Phenom II X2

  • MEMORY: 4Gb

  • VIDEO CARD: AMD Mullin Radeon R2//Intel//AMD/ATI RS880
I'm not a CRON expert but....
If not executing, maybe a permissions issue??
Any error's when running?? May have to pipe it out to a txt file to see errors..



LL 4.4 UEFI 64 bit ASUS E402W - AMD E2 (Quad) 1.5Ghz  - 4GB - AMD Mullins Radeon R2
LL 4.4 64 bit HP 6005- AMD Phenom II X2 - 8GB - AMD/ATI RS880 (HD4200)
LL 4.4 UEFI 64 bit Test UEFI Kangaroo (Mobile Desktop) - Atom X5-Z8500 1.44Ghz - 2GB - Intel HD Graphics
LL 3.8 32 bit Dell Inspiron Mini - Atom N270 1.6Ghz - 1GB - Intel Mobile 945GSE Express
RETIRED LL 2.8 64 bit Dell Optiplex 160 (Thin) - Atom 230 1.6Ghz - 4GB-SiS 771/671 PCIE VGA
Running Linux Lite since LL2.2
 

Re: Cron job to automate backup????
« Reply #2 on: December 14, 2015, 10:00:25 AM »
 

Wirezfree

  • PayPal Supporter
  • Platinum Level Poster
  • *****
  • 1484
    Posts
  • Country: gb
  • Reputation: 404
  • Linux Lite "Advocate"

  • Linux Lite: 2.8 64bit

  • CPU: i7-4790S

  • MEMORY: 16Gb

  • VIDEO CARD: Intel HD4600 (Integrated)
Not sure if it's similar..??
I had some permissions issue trying to run some tasks...
If you run gnome-scheduler from the System menu,
The tasks are only run as "normal user".

But if you open a terminal and do:
Code: [Select]
gksu gnome-scheduler

It now run's as root, so anything you now schedule this way run's with root privileges.
If you open Scheduler from the menu, you do not see the(se) root tasks.
Upgrades WIP 2.6 to 2.8 - (6 X 2.6 to 2.8 completed on: 20/02/16 All O.K )
Linux Lite 3.0 Humming on a ASRock N3070 Mobo ~ btrfs RAID 10 Install on 4 Disks :)

Computers Early days:
ZX Spectrum(1982) , HP-150 MS-DOS(1983) , Amstrad CPC464(1984) ,  BBC Micro B+64(1985) , My First PC HP-Vectra(1987)
 

Re: Cron job to automate backup????
« Reply #3 on: December 14, 2015, 11:34:07 AM »
 

kjacobs

  • Occasional Poster
  • **
  • 71
    Posts
  • Reputation: 5
  • Linux Lite Member

  • CPU: 2x Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz

  • MEMORY: 4Gb
Thanks for the replies......yes, I thought it might be a permissions things as well. I have a copy of backup.sh in a user folder with my user ownership and a copy in /usr/bin/ with root ownership. Neither one seem to run, yet I can double click either and it launches fine. All I seem to get in syslog for this line is this....



Dec 14 08:15:01 kenneth-OptiPlex-755 CRON[8245]: (root) CMD (/usr/bin/backup.sh)
Dec 14 08:15:01 kenneth-OptiPlex-755 CRON[8244]: (CRON) info (No MTA installed, discarding output)


I am not trying to mail anything, as the file should launch and I should see grsync start running when it hits the correct time. It looks like it is "trying" to run???? But nothing is happening.....maybe I am wrong here?
 

Re: Cron job to automate backup????
« Reply #4 on: December 14, 2015, 11:40:07 AM »
 

Wirezfree

  • PayPal Supporter
  • Platinum Level Poster
  • *****
  • 1484
    Posts
  • Country: gb
  • Reputation: 404
  • Linux Lite "Advocate"

  • Linux Lite: 2.8 64bit

  • CPU: i7-4790S

  • MEMORY: 16Gb

  • VIDEO CARD: Intel HD4600 (Integrated)
Upgrades WIP 2.6 to 2.8 - (6 X 2.6 to 2.8 completed on: 20/02/16 All O.K )
Linux Lite 3.0 Humming on a ASRock N3070 Mobo ~ btrfs RAID 10 Install on 4 Disks :)

Computers Early days:
ZX Spectrum(1982) , HP-150 MS-DOS(1983) , Amstrad CPC464(1984) ,  BBC Micro B+64(1985) , My First PC HP-Vectra(1987)
 

Re: Cron job to automate backup????
« Reply #5 on: December 14, 2015, 11:55:04 AM »
 

kjacobs

  • Occasional Poster
  • **
  • 71
    Posts
  • Reputation: 5
  • Linux Lite Member

  • CPU: 2x Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz

  • MEMORY: 4Gb
Thanks for the tip.....that at least got some info on what is going on......got this from the mail file:



Subject: Cron <root@kenneth-OptiPlex-755> DISPLAY=:0.0 /home/kenneth/bin/backup.sh # JOB_ID_3
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20151214165201.DA4455E165B@kenneth-OptiPlex-755>
Date: Mon, 14 Dec 2015 08:52:01 -0800 (PST)


No protocol specified


(grsync:11062): Gtk-WARNING **: cannot open display: :0.0


Not sure what this means....LOL. Also tried it without the DISPLAY command......still did not start.



Subject: Cron <root@kenneth-OptiPlex-755> /home/kenneth/bin/backup.sh >/home/kenneth/bin/text.txt # JOB_ID_3
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20151214164801.BDA305E165B@kenneth-OptiPlex-755>
Date: Mon, 14 Dec 2015 08:48:01 -0800 (PST)




(grsync:10646): Gtk-WARNING **: cannot open display:
Last Edit: December 14, 2015, 11:56:55 AM by kjacobs
 

Re: Cron job to automate backup????
« Reply #6 on: December 14, 2015, 12:45:11 PM »
 

firenice03

  • Rockin' the FREE World
  • Platinum Level Poster
  • **********
  • 1105
    Posts
  • Country: us
  • Reputation: 220
  • Linux Lite Member

  • Linux Lite: 4.4 64bit

  • CPU: AMD E2//Atom X5//AMD Phenom II X2

  • MEMORY: 4Gb

  • VIDEO CARD: AMD Mullin Radeon R2//Intel//AMD/ATI RS880
Quote
(grsync:11062): Gtk-WARNING **: cannot open display: :0.0
Looks like its trying to launch a GUI of sorts..???..??
http://askubuntu.com/questions/614387/gksu-gtk-warning-cannot-open-display-0

Another thought.. isn't CRON (sh) shell based and terminal is BASH... Not sure if this is still the case/true...
But the script runs in terminal and fails in cron - I assume it fails from any shell window...

Maybe its trying to prompt for roots PW??
Something like.. http://stackoverflow.com/questions/22704290/linux-cron-job-fails-to-execute-part-of-script-which-works-in-shell

Hope it helps point in the right direction...
LL 4.4 UEFI 64 bit ASUS E402W - AMD E2 (Quad) 1.5Ghz  - 4GB - AMD Mullins Radeon R2
LL 4.4 64 bit HP 6005- AMD Phenom II X2 - 8GB - AMD/ATI RS880 (HD4200)
LL 4.4 UEFI 64 bit Test UEFI Kangaroo (Mobile Desktop) - Atom X5-Z8500 1.44Ghz - 2GB - Intel HD Graphics
LL 3.8 32 bit Dell Inspiron Mini - Atom N270 1.6Ghz - 1GB - Intel Mobile 945GSE Express
RETIRED LL 2.8 64 bit Dell Optiplex 160 (Thin) - Atom 230 1.6Ghz - 4GB-SiS 771/671 PCIE VGA
Running Linux Lite since LL2.2
 

Re: Cron job to automate backup????
« Reply #7 on: December 14, 2015, 12:48:10 PM »
 

Wirezfree

  • PayPal Supporter
  • Platinum Level Poster
  • *****
  • 1484
    Posts
  • Country: gb
  • Reputation: 404
  • Linux Lite "Advocate"

  • Linux Lite: 2.8 64bit

  • CPU: i7-4790S

  • MEMORY: 16Gb

  • VIDEO CARD: Intel HD4600 (Integrated)
I'm just stabbing in the dark....
Grsync is a GUI version of rsync..
Maybe that is the Gtk-WARNING cannot open display
Maybe it's trying to output something GUI-wise but it is not running a gui..??
I'm probably not making sense...

Can you not try just rsync..??
Upgrades WIP 2.6 to 2.8 - (6 X 2.6 to 2.8 completed on: 20/02/16 All O.K )
Linux Lite 3.0 Humming on a ASRock N3070 Mobo ~ btrfs RAID 10 Install on 4 Disks :)

Computers Early days:
ZX Spectrum(1982) , HP-150 MS-DOS(1983) , Amstrad CPC464(1984) ,  BBC Micro B+64(1985) , My First PC HP-Vectra(1987)
 

Re: Cron job to automate backup????
« Reply #8 on: December 14, 2015, 12:50:16 PM »
 

Wirezfree

  • PayPal Supporter
  • Platinum Level Poster
  • *****
  • 1484
    Posts
  • Country: gb
  • Reputation: 404
  • Linux Lite "Advocate"

  • Linux Lite: 2.8 64bit

  • CPU: i7-4790S

  • MEMORY: 16Gb

  • VIDEO CARD: Intel HD4600 (Integrated)
@firenice03
great minds, well hopefully great minds....
Upgrades WIP 2.6 to 2.8 - (6 X 2.6 to 2.8 completed on: 20/02/16 All O.K )
Linux Lite 3.0 Humming on a ASRock N3070 Mobo ~ btrfs RAID 10 Install on 4 Disks :)

Computers Early days:
ZX Spectrum(1982) , HP-150 MS-DOS(1983) , Amstrad CPC464(1984) ,  BBC Micro B+64(1985) , My First PC HP-Vectra(1987)
 

Re: Cron job to automate backup????
« Reply #9 on: December 14, 2015, 12:53:37 PM »
 

firenice03

  • Rockin' the FREE World
  • Platinum Level Poster
  • **********
  • 1105
    Posts
  • Country: us
  • Reputation: 220
  • Linux Lite Member

  • Linux Lite: 4.4 64bit

  • CPU: AMD E2//Atom X5//AMD Phenom II X2

  • MEMORY: 4Gb

  • VIDEO CARD: AMD Mullin Radeon R2//Intel//AMD/ATI RS880
@firenice03
great minds, well hopefully great minds....

Yours yes... Mine - I'm getting there  8)  I'm good with "google"....

Yeah - looks like the App is trying to access the display.. This may help..??..
http://promberger.info/linux/2009/01/02/running-x-apps-like-zenity-from-crontab-solving-cannot-open-display-problem/

LL 4.4 UEFI 64 bit ASUS E402W - AMD E2 (Quad) 1.5Ghz  - 4GB - AMD Mullins Radeon R2
LL 4.4 64 bit HP 6005- AMD Phenom II X2 - 8GB - AMD/ATI RS880 (HD4200)
LL 4.4 UEFI 64 bit Test UEFI Kangaroo (Mobile Desktop) - Atom X5-Z8500 1.44Ghz - 2GB - Intel HD Graphics
LL 3.8 32 bit Dell Inspiron Mini - Atom N270 1.6Ghz - 1GB - Intel Mobile 945GSE Express
RETIRED LL 2.8 64 bit Dell Optiplex 160 (Thin) - Atom 230 1.6Ghz - 4GB-SiS 771/671 PCIE VGA
Running Linux Lite since LL2.2
 

Re: Cron job to automate backup????
« Reply #10 on: December 15, 2015, 11:51:44 AM »
 

kjacobs

  • Occasional Poster
  • **
  • 71
    Posts
  • Reputation: 5
  • Linux Lite Member

  • CPU: 2x Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz

  • MEMORY: 4Gb
Well fellas.....I tried a few more options from the links you provided, but still had no luck running grsync. It appears the GUI for rsync is fussy about starting from cron or scheduler.


So, I decided to grab the rsync command that grsync was sending and dropped that direct into scheduler......that seemed to work fine. Then I copied that command into my backup.sh script and ran the shell script from scheduler.....that worked fine too. I even setup rsync to send a log file of the backup, so I can see that everything went fine.


Thanks for the help......
Last Edit: December 15, 2015, 11:53:35 AM by kjacobs
 

Re: Cron job to automate backup????
« Reply #11 on: December 15, 2015, 12:24:34 PM »
 

Wirezfree

  • PayPal Supporter
  • Platinum Level Poster
  • *****
  • 1484
    Posts
  • Country: gb
  • Reputation: 404
  • Linux Lite "Advocate"

  • Linux Lite: 2.8 64bit

  • CPU: i7-4790S

  • MEMORY: 16Gb

  • VIDEO CARD: Intel HD4600 (Integrated)
glad you sorted it... GL
Upgrades WIP 2.6 to 2.8 - (6 X 2.6 to 2.8 completed on: 20/02/16 All O.K )
Linux Lite 3.0 Humming on a ASRock N3070 Mobo ~ btrfs RAID 10 Install on 4 Disks :)

Computers Early days:
ZX Spectrum(1982) , HP-150 MS-DOS(1983) , Amstrad CPC464(1984) ,  BBC Micro B+64(1985) , My First PC HP-Vectra(1987)
 

Re: Cron job to automate backup????
« Reply #12 on: December 15, 2015, 01:19:32 PM »
 

firenice03

  • Rockin' the FREE World
  • Platinum Level Poster
  • **********
  • 1105
    Posts
  • Country: us
  • Reputation: 220
  • Linux Lite Member

  • Linux Lite: 4.4 64bit

  • CPU: AMD E2//Atom X5//AMD Phenom II X2

  • MEMORY: 4Gb

  • VIDEO CARD: AMD Mullin Radeon R2//Intel//AMD/ATI RS880
LL 4.4 UEFI 64 bit ASUS E402W - AMD E2 (Quad) 1.5Ghz  - 4GB - AMD Mullins Radeon R2
LL 4.4 64 bit HP 6005- AMD Phenom II X2 - 8GB - AMD/ATI RS880 (HD4200)
LL 4.4 UEFI 64 bit Test UEFI Kangaroo (Mobile Desktop) - Atom X5-Z8500 1.44Ghz - 2GB - Intel HD Graphics
LL 3.8 32 bit Dell Inspiron Mini - Atom N270 1.6Ghz - 1GB - Intel Mobile 945GSE Express
RETIRED LL 2.8 64 bit Dell Optiplex 160 (Thin) - Atom 230 1.6Ghz - 4GB-SiS 771/671 PCIE VGA
Running Linux Lite since LL2.2
 

Re: Cron job to automate backup????
« Reply #13 on: June 11, 2018, 09:11:46 PM »
 

kpanic

  • PayPal Supporter
  • Forum Regular
  • *****
  • 162
    Posts
  • Country: fi
  • Reputation: 66
  • Linux Lite Member

  • Linux Lite: 4.0 64bit

  • CPU: Core i5 M450

  • MEMORY: 8Gb

  • VIDEO CARD: Nvidia GT216
Hi,

You need to set EDITOR environment variable to some text editor.
I use nano here, you may use emacs, vi or anything really
For example:

shell >  export EDITOR=nano
shell >  crontab -e

## Insert or append a line like:
# min hour day_of_the_month   month   day_of_the_week   command
# So 5 past midnight of every Tuesday do...

5 0 * * 2  tar -cf   ~/back.tar  ~/Documents && mv ~/back.tar  /where-ever  2>&1 > /dev/null

# Save settings = CTRL+O
# exit = CTRL+X

Last Edit: June 11, 2018, 09:24:20 PM by kpanic
 


Tags:
 


Linux Lite 4.6 RC1 has been released. See the Release Announcements section for more information.