Shell script to make full backup?

Issues related to applications and software problems
Post Reply
johnsie
Posts: 6
Joined: 2013/05/17 15:09:51

Shell script to make full backup?

Post by johnsie » 2015/07/14 19:18:23

Hi,
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?

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: Shell script to make full backup?

Post by gerald_clark » 2015/07/14 19:31:23

$DIR is unused
-f specifies a non-excluded file.

General linux questions belong in a linux forum.

johnsie
Posts: 6
Joined: 2013/05/17 15:09:51

Re: Shell script to make full backup?

Post by johnsie » 2015/07/14 19:35:06

Thanks. Taking out the DIR and the f didn't make it work. I will join a Linux form and ask there instead.

drk
Posts: 405
Joined: 2014/01/30 20:38:28

Re: Shell script to make full backup?

Post by drk » 2015/07/15 02:31:54

johnsie wrote: 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."
One problem is that it looks like you're putting the archive in the wrong spot.

Post Reply