Linux Cron Backup Script – run once every month via cron

  Linux Cron Backup Script
==========

I set cron job with crontab -e for running 20:20 8th everyMonth any weekDay

Script appears below as backup-cron.sh,… feel free to COPY to your Linux VM for experimentation…

[root@server1 backup-cron]# crontab -l

20 20 8 * * /root/backup-cron.sh

[root@server1 backup-cron]# cd
[root@server1 ~]# cat backup-cron.sh
#!/usr/bin/bash

# script: /root/backup-cron.sh
# Author LEONIDAS SAVVIDES - LSEPOLIS123@GMAIL.COM
# script for backup auto with cron the Directory /etc/ to /root/backup-cron/etc-YYYY-MM-DD.tar.bz2 type
# of Archives once a month the 8th of each month 20:00

# Get Current date in format YYYY-MM-DD

DATE=`date +%Y-%m-%d`;

# directory to backup
BACKUP_THIS_DIR="/etc";

# save backups in the name /root/backup-cron/etc-DATE.tar.bz2

BACKUP_TO="/root/backup-cron/";

EXT=".tar.bz2";

BACKUP_FILE="etc-"$DATE$EXT; # not spaced

FULL_BACKUP_URI=$BACKUP_TO$BACKUP_FILE;  # not spaced

# Command to execute

tar jcvf $FULL_BACKUP_URI $BACKUP_THIS_DIR;  # all spaced with one space

# check if success or failure backup done
if [ $? -eq 0 ]; then
echo "Success"; mail -s "Success Backup on "$DATE root@localhost; exit 0;
else
echo "Failure"; mail -s "Failed Backup on "$DATE root@localhost; exit 1;
fi

# END OF THE SCRIPT

[root@server1 ~]#

any Question email me here : 

LSEPOLIS123@GMAIL.COM