I read in a tutorial that I could use the following command to make a full backup of my system:
Code: Select all
tar cvpzf /backups/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backups --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/sysconfig/network-scripts/ --exclude=/etc/udev/rules.d/70-persistent-net.rules /
That works great for me in the command line. I have tested it and the recovery went well. I would like to be able for this to happen automatically each night .but when I try to do it in a bash script it gives me an error message that it can't stat the directory. I know how to make a cron job to execute a shell script, but this code is not working to make the backup:
Code: Select all
#!/bin/bash
#Generic Server Backup With tar
DIR="serverbackup"
DATE=`date +%a-%d-%b-%Y-%I:%M:%S-%p-%Z`
SERVER=`uname -n`
echo "Starting backup for $SERVER..."
cd /
tar cvpzf /home/backup/$DATE-backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backups --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/sysconfig/network-scripts/ --exclude=/etc/udev/rules.d/70-persistent-net.rules /
echo "Done."
Anyone out there know what I'm doing wrong or how I can fix it?