Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

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....

Posted

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?

Posted

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)

Posted

Eek! good spot powdarrmonkey!!

@tom_newton - the cron job runs at 00:00 so date should have already changed before it runs!

Posted
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?
Posted
root@web01:~# cat /etc/aliases
# See man 5 aliases for format
postmaster:    root
[email="root@web01"]root@web01[/email]:~#

Posted

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.

Posted (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 by Gatt
Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...