*nix Thread, Cronjob oddity in Technical; I use the following script to create a gzipped tarball of my main website (/var/www/) and another of our extra ...
16th February 2010, 10:40 AM #1
I use the following script to create a gzipped tarball of my main website (/var/www/) and another of our extra sites with a datestamp on the file name:
When I run the script manually with
/bin/tar -cvf /backups/websites.tar /usr/share/websites/
mkdir -p /backups/websites/`/bin/date +%Y/%b`
/bin/mv /backups/websites.tar.gz /backups/websites/`/bin/date +%Y/%b/websites_%d-%b-%Y.tar.gz`
/bin/tar -cvf /backups/joomla.tar /var/www/
mkdir -p /backups/joomla/`/bin/date +%Y/%b`
/bin/mv /backups/joomla.tar.gz /backups/joomla/`/bin/date +%Y/%b/joomla_%d-%b-%Y.tar.gz`
It works perfectly (about 24M for Joomla, and about 1.5GB for the websites)
However when I run the same script via crontab, it only creates a tarball about 300k in size?
Am stumped as to why it doesnt work as a cronjob....
@daily /path/to/scripts/scriptname.sh #Backup all websites
IDG Tech News
16th February 2010, 10:44 AM #2
cron job running as a user who cn't read those files?
16th February 2010, 10:45 AM #3
Nope - running as root - other cronjob runs fine - does the same thing with mysql (mysqldump, gzip with date appeneded..)
Wondering if cron timse out at all?
16th February 2010, 10:49 AM #4
Try re-ordering it - make the directory first, and then do the tar as a one liner (add "z" to the commandline opts to make it zip automatically).
16th February 2010, 10:50 AM #5
Oooh... and check that the output of "date" isn't changing while your cron is taking place. You might stick that in a variable first before use.
16th February 2010, 10:51 AM #6
Default installations of cron on Ubuntu mail the job output to root, unless you redirect it (which you haven't). Take a look there.
You also don't have a bang (!) in your shebang, line 1 (should read #!/bin/sh)
16th February 2010, 10:52 AM #7
Eek! good spot powdarrmonkey!!
@tom_newton - the cron job runs at 00:00 so date should have already changed before it runs!
16th February 2010, 10:55 AM #8
Also @ powdarrmonkey - i cant read teh system mail?? installed mutt and ran it as root and main user (the one created at install) but all empty?
16th February 2010, 11:06 AM #9
Check cat /var/mail/root or /var/spool/mail/root? See if it's being directed somewhere else (/dev/null is a favourite) in /etc/aliases.
16th February 2010, 11:08 AM #10
nothing in /var/mail or /var/spool/mail (which is ointing to /var/mail/ anyway!)
16th February 2010, 11:11 AM #11
Always worth a check How about /etc/aliases?
16th February 2010, 11:12 AM #12
root@web01:~# cat /etc/aliases
# See man 5 aliases for format
16th February 2010, 11:16 AM #13
Hmm. Ubuntu folks do even more silly things than I thought.
In that case, redirect it to a log file yourself - in cron,
It will be easier to read if you do the gzip inline, as Tom suggests:
@daily /path/to/scripts/scriptname.sh > /var/mail/mybackup.log 2>&1 #Backup all websites
and get rid of the calls to gzip. Add the -v (verbose) flag to your calls to mv too.
/bin/tar -czvf /backups/joomla.tar.gz /var/www/
16th February 2010, 11:18 AM #14
can I still datestamp it that way
Would be a heck of a ot easier i admit..
gonna redirect it to /var/log/backups/websites.log - does it need to be >> though to append?
Last edited by Gatt; 16th February 2010 at 11:20 AM.
16th February 2010, 11:22 AM #15
Yes, your mv command will still rename it, you're just combining the tar and gzip steps (why have two processes when tar can do it all? )
Thanks to powdarrmonkey from:
Gatt (16th February 2010)
By cookie_monster in forum Windows
Last Post: 7th July 2008, 11:33 AM
Last Post: 21st April 2006, 09:22 AM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)