Shell Script back up Centos
In the tutorial, I read that I can use the following command to create a complete backup of my CENTOS system:
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 /
This works great for me on the command line. I tested it and the recovery went well. I wish this could happen automatically every night, but when I try to do it in a bash script it gives me some error messages. I know how to make a cron job to execute a shell script, but this code doesn't work to create a backup:
#!/bin/bash
#Generic Server Backup With tar
SERVER=`uname -n`
echo "Starting backup for $SERVER..."
tar cvpzf /home/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 /
echo "Done."
Does anyone know what I am doing wrong or how I can fix this?
Error messages:
sh bu.sh
...rting backup for juice.myserver.com
tar: Removing leading `/' from member names
tar: /\r: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
Done.
source to share
The problem seems to be related to the CR (carriage return) at the end of the tar command.
After the exclusion, the single forward slash (/) is removed, which is obviously the outline that will fall back. The problem is that tar considers it // r and obviously doesn't exist.
The recommendation is to try to use some utility like dos2unix
or use some command like this tr -d '\r' < bu.sh > newbu.sh
to remove it.
After that, it should work properly.
source to share