less backup-simple-rsync-bash-script.md
Backup: simple rsync bash script
# archivio storico — scritto anni fa, conservato com'era. Alcune info sono datate.
With the following script you can backup entire system or one directory. The script provides incremental backup and a log file for each backup session.
#!/bin/bash
date=`date "+%Y-%m-%dT%H_%M_%S"`
# Setup Directory Variables
BACKUPHOME=/home/backup
DIR2BCK=/etc
# Rsync All Data in local Dir
rsync -azP \
--delete \
--delete-excluded \
--log-file=$BACKUPHOME/back-$date-incomplete-LOGFILE.txt --stats \
--exclude-from=$BACKUPHOME/.rsync/exclude \
--link-dest=../current \
$DIR2BCK $BACKUPHOME/incomplete_back-$date
# Create incremental DIR and current link
mv $BACKUPHOME/incomplete_back-$date $BACKUPHOME/back-$date \
&& mv $BACKUPHOME/back-$date-incomplete-LOGFILE.txt $BACKUPHOME/back-$date-LOGFILE.txt \
&& rm -f $BACKUPHOME/current \
&& rm -f $BACKUPHOME/current-log \
&& ln -s $BACKUPHOME/back-$date $BACKUPHOME/current \
&& ln -s $BACKUPHOME/back-$date-LOGFILE.txt $BACKUPHOME/current-log
# Add disk usage for each backup to log file
cd $BACKUPHOME/ && du -shc back-* >> $BACKUPHOME/current-log
Try to put this script in /etc/cron.daily/
In this example I do a backup of my /etc/ directory every time, but you can change this variables with your web site root directory