Jump to: navigation, search

Backup Script for Remote Server

From w3cyberlearnings

Backup file

This backup script uses to backup a specific directory and send to a storage.

root@htvlc:/var/backup_totara# cat bkup-totara.sh 
DATE=`date +"%Y%m%d"`
HOUR=`date +%H`
BKDIR="/var/backup_totara/remote-disk/"
DAYSOLD="7"
DATADIR="/var/totara"
OFFDIR="/var/backup_totara/remote-disk/"
LOGDIR="/var/backup_totara/remote-disk/log/"

if [ $HOUR -eq 0 ]
        then 
		NUM=1 
	elif [ $HOUR -eq 6 ]
        then
                NUM=2
        elif [ $HOUR -eq 12 ]
        then
                NUM=3
        elif [ $HOUR -eq 18 ]
        then
                NUM=4
        else
                NUM="TEST"
fi

TODAY="$DATE-$NUM"

sudo mount -o soft,intr,rsize=8192,wsize=8192 10.1.0.170:/mnt/tvlcbk $OFFDIR

echo "Started CPIO Backup at `date`\n" > $LOGDIR/${TODAY}_backup.log
find $DATADIR -depth -print | grep -v $DATADIR/data/sessions/ 
| cpio -oc > $BKDIR/${TODAY}_cpio-totara_src-backup
echo "Completed CPIO Backup at `date`\n" >> $LOGDIR/${TODAY}_backup.log

echo "Started Database Dump of TotaraDB at `date`\n" >> $LOGDIR/${TODAY}_backup.log
pg_dump -h localhost -U postgres totaradb > $BKDIR/${TODAY}_dump-totaradb-backup 
echo "Completed Database Dump of TotaraDB at `date`\n" >> $LOGDIR/${TODAY}_backup.log


ls -lh $BKDIR/*cpio* | awk 'BEGIN {print ""}{ print $6 "  " $7 "  " $5 "  " $8}' >> 
$LOGDIR/${TODAY}_backup.log
ls -lh $BKDIR/*dump* | awk 'BEGIN {print ""}{ print $6 "  " $7 "  " $5 "  " $8}' >> 
$LOGDIR/${TODAY}_backup.log

find $BKDIR/*backup* -mtime +$DAYSOLD -exec rm -f {} \;
find $LOGDIR/*.log* -mtime +$DAYSOLD -exec rm -f {} \;

sudo umount $OFFDIR

Mount Directory

Use to mount the directory

root@htvlc:/var/backup_totara# cat mount-bkdrv.sh 
OFFDIR="/var/backup_totara/remote-disk/"

sudo mount -o soft,intr,rsize=8192,wsize=8192 10.1.0.170:/mnt/tvlcbk $OFFDIR

Unmount Directory

Use to unmount the directory

root@htvlc:/var/backup_totara# cat umount-bkdrv.sh 
OFFDIR="/var/backup_totara/remote-disk/"

sudo umount $OFFDIR

Navigation
Web
SQL
MISC
References