MatsB
April 7th, 2009, 11:52 AM
Hi,
For some reason my cron job does not compress all my files so I’m assuming that it’s a permission issue with the cron job. When I run the tar command manually with sudo it works ok. The cron job is added with [sudo cronjob –e]
The first file is done with the cron job and the second with sudo ./backup_script.sh
-rw-r--r-- 1 root root 90800 2009-04-07 12:40 backup-2009-04-07-0815.tar.gz
-rw-r--r-- 1 root root 150313177 2009-04-03 08:15 backup-2009-04-07-0826.tar.gz
ubuntu:~$ sudo crontab -l -u root
# m h dom mon dow command
0 1 * * * /etc/cron.daily/backup_script.sh
I’ve created a simple bash script that looks like this:
ubuntu:~$ ls -l /etc/cron.daily/backup_script.sh
-rwxr-xr-x 1 root root 177 2009-04-07 09:42 backup_script.sh
#!/bin/bash
backupdir1=/etc/
backupdir2=/home/
filename="backup-$(date '+%F-%H%M').tar.gz"
echo "Creating a backup file $filename of $backupdir."
# Make a tar gzipped backup file
tar -cvzf "$filename" "$backupdir1" "$backupdir2”
For some reason my cron job does not compress all my files so I’m assuming that it’s a permission issue with the cron job. When I run the tar command manually with sudo it works ok. The cron job is added with [sudo cronjob –e]
The first file is done with the cron job and the second with sudo ./backup_script.sh
-rw-r--r-- 1 root root 90800 2009-04-07 12:40 backup-2009-04-07-0815.tar.gz
-rw-r--r-- 1 root root 150313177 2009-04-03 08:15 backup-2009-04-07-0826.tar.gz
ubuntu:~$ sudo crontab -l -u root
# m h dom mon dow command
0 1 * * * /etc/cron.daily/backup_script.sh
I’ve created a simple bash script that looks like this:
ubuntu:~$ ls -l /etc/cron.daily/backup_script.sh
-rwxr-xr-x 1 root root 177 2009-04-07 09:42 backup_script.sh
#!/bin/bash
backupdir1=/etc/
backupdir2=/home/
filename="backup-$(date '+%F-%H%M').tar.gz"
echo "Creating a backup file $filename of $backupdir."
# Make a tar gzipped backup file
tar -cvzf "$filename" "$backupdir1" "$backupdir2”