Simple script to backup a folder in a tar.gz file.
#!/bin/bash
#Purpose = Backup of /myfolder folder
#Created on 22-10-2016
#Author = Albes
#Version 1.0
#START
TIME=$(date +%Y%m%d) # To add date in Backup File Name
echo $TIME FILENAME=file_backup-$TIME.tar.gz # Here i define Backup file name format SRCDIR=/var/www/html # Location of Important Data Directory (Source of backup). For example your site web /var/www/html
DESDIR=/home # Destination of backup file
tar cpzf $DESDIR/$FILENAME $SRCDIR
find . -mtime +7 -exec rm -f {} \; #remove files older than 7 days. Change this value at your convenience
#END
Once you have complete your script you can also execute it with crontab every day at 3:00 am. For example:
# m h dom mon dow command 0 3 * * * /home/my_backup_script.sh
No comments:
Post a Comment