Click to See Complete Forum and Search --> : script for backup data on weekly basis??
ccn-c09
12-11-2003, 10:55 PM
Hi all:
I would like to backup my e-mail server data to tape on weekly basis like full backup on every sat night. Could someone give me a hints or ideas on how it can be done bcos I have very little experience on linux
Any helps would be great appreaciated!!
cheers
voidinit
12-11-2003, 11:10 PM
Originally posted by ccn-c09
Hi all:
I would like to backup my e-mail server data to tape on weekly basis like full backup on every sat night. Could someone give me a hints or ideas on how it can be done bcos I have very little experience on linux
Any helps would be great appreaciated!!
cheers
#!/bin/bash
if [ `id -u` != 0 ]; then
echo "You must be root to do this man, what where you thinking?"
exit 1;
fi
#Make sure /mnt/mp3 is mounted
if grep -w /mnt/backup /etc/mtab 1> /dev/null 2> /dev/null; then
echo "/mnt/backup is mounted already"
mountbackup="1"
else
echo "Attempting to mount /mnt/backup using /etc/fstab"
/sbin/mount /mnt/backup
if [ echo $? != "0" ]; then
echo "Failure Mounting /mnt/backup"
exit 1;
fi
echo "Success!"
mountbackup="0"
fi
#Make sure /mnt/backup is mounted
if grep -w /mnt/mp3 /etc/mtab 1> /dev/null 2>/dev/null; then
echo "/mnt/mp3 is mounted already"
mountmp3="1"
else
echo "Attempting to mount /mnt/mp3 using /etc/fstab"
/sbin/mount /mnt/mp3
if [ echo $? != "0" ]; then
echo "Failure mounting /mnt/mp3"
exit 1;
fi
echo "Success!"
mountmp3="0"
fi
echo "Clearing Log File"
echo " " > /var/log/mp3backup.log
echo "Starting backup @ `date`"
echo "Logging to /var/log/mp3backup.log"
cp -Rv /mnt/mp3/* /mnt/backup 1> /var/log/mp3backup.log 2> /var/log/mp3backup.sh
#If mnt/backup and /mnt/mp3 weren't mounted to begin wtih, unmount them
if [ $mountbackup = "0" ]; then
echo "Unmount /mnt/backup"
umount /mnt/backup
fi
if [ $mountmp3 = "0" ]; then
echo "Unmounting /mnt/mp3"
umount /mnt/mp3
fi
Here is a script i use to backup my .mp3s on a daily basis. When run it checks my source partition to make sure it is mounted, if it's not, it mounts it. Then it checks to see if my destination parition is mounted (my destination is a samba share on another box), if its not mounted it mounts it. Then it uses cp -R to copy the files over. you could use tar or gzip or whatever you wanted. I had it setup to use zip but that was just too slow and you really don't gain much when zipping .mp3s. After the copy is complete it checks to see wether or not it had to mount the source and destination and if it did have to mount them then it unmounts them. It also logs what is backed up.
Just drop something similar in /etc/cron.weekly, make sure it's executable, and you should be good to go.
I highly recommend the Advanced Bash Scripting Guide from TLDP (http://www.tldp.org).
ccn-c09
12-12-2003, 02:00 AM
thanks for ur quick reply voidinit
i really appreciated that...
i'll definitely look into the Advanced Bash Scripting Guide from TLDP that u have mentioned..that should be good for me to start with
hopefully i will be able to get it done by end of next week bcos it's productive server so i can't really leave it on it's own without any backup...
ideally. i would like to perform incermental backup (tar possible) for the /home /var ...it should be harder to implement ..well time will tell...
thanks again
cheers