Friday, 22 June 2012

Backup script

Backup Script document in linux


#! /bin/bash
# What to backup.
SOURCE="/source"

# Where to backup to.
DEST1="/backup"


# Backup the files
tar vczf $DEST1/$(date +%m-%d).tar.gz $SOURCE


echo "Backup finished"
date


#To remove 2 days before old files

# Remove old backup file
if [ -f /dest/$(date -d 'now -2 days' '+%m-%d').tar.gz ]
then
echo "exists"
rm -rf /dest/$(date -d 'now -2 days' '+%m-%d').tar.gz
fi


This script is used to take a backup of a seperate folder and stored in a location. We can add more source and target location by adding source and dest  commands. The final part of the script is to delete the backup which is older than days, you just edit the number according to your requirment. If any doubts please reply i ll solve your doubts.

Thanks
Viswa

1 comment: