Gatt Posted February 16, 2010 Posted February 16, 2010 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: #/bin/sh /bin/tar -cvf /backups/websites.tar /usr/share/websites/ /bin/gzip /backups/websites.tar 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/ /bin/gzip /backups/joomla.tar 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` When I run the script manually with /path/to/scripts/scriptname.sh 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? cronjob is: @daily /path/to/scripts/scriptname.sh #Backup all websites Am stumped as to why it doesnt work as a cronjob....
tom_newton Posted February 16, 2010 Posted February 16, 2010 cron job running as a user who cn't read those files?
Gatt Posted February 16, 2010 Author Posted February 16, 2010 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?
tom_newton Posted February 16, 2010 Posted February 16, 2010 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).
tom_newton Posted February 16, 2010 Posted February 16, 2010 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.
powdarrmonkey Posted February 16, 2010 Posted February 16, 2010 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)
Gatt Posted February 16, 2010 Author Posted February 16, 2010 Eek! good spot powdarrmonkey!! @tom_newton - the cron job runs at 00:00 so date should have already changed before it runs!
Gatt Posted February 16, 2010 Author Posted February 16, 2010 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?
powdarrmonkey Posted February 16, 2010 Posted February 16, 2010 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.
Gatt Posted February 16, 2010 Author Posted February 16, 2010 nothing in /var/mail or /var/spool/mail (which is ointing to /var/mail/ anyway!)
powdarrmonkey Posted February 16, 2010 Posted February 16, 2010 Always worth a check How about /etc/aliases?
Gatt Posted February 16, 2010 Author Posted February 16, 2010 root@web01:~# cat /etc/aliases # See man 5 aliases for format postmaster: root [email="root@web01"]root@web01[/email]:~#
powdarrmonkey Posted February 16, 2010 Posted February 16, 2010 Hmm. Ubuntu folks do even more silly things than I thought. In that case, redirect it to a log file yourself - in cron, @daily /path/to/scripts/scriptname.sh > /var/mail/mybackup.log 2>&1 #Backup all websites It will be easier to read if you do the gzip inline, as Tom suggests: /bin/tar -czvf /backups/joomla.tar.gz /var/www/ and get rid of the calls to gzip. Add the -v (verbose) flag to your calls to mv too.
Gatt Posted February 16, 2010 Author Posted February 16, 2010 (edited) 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? Edited February 16, 2010 by Gatt
powdarrmonkey Posted February 16, 2010 Posted February 16, 2010 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? ) 1
Gatt Posted February 16, 2010 Author Posted February 16, 2010 Thanks - editted the scripts and the cron jobs now.. Will need to check them tomorrow on the way down to Unimatrix Zero .. err sorry RM HQ - lol
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now