Rsync Incremental Daily Backup

#!/bin/bash
# SSH keys need to be added so that the backup can be transferred to backup server.
# By Sileep Kumar M S <sileepkumar@gmail.com>

# Source Directory
SRC=/home
# Destination server IP
HOST=192.168.2.16     
# Destination Directory Name
DST_DIR=/BACKUPS      
# Assuming SSH port is 22
PORT=22               
# A list of files or directories to exclude.
EXCLUDES=/root/excludes.txt    

# Rsync binary path
RSYNC=/usr/bin/rsync
# Custom ssh command (like ssh -i keyfile -l remote_user)
SSH=/usr/bin/ssh

#Todays date in ISO-8601 format:
DAY0=`date -I`
#Yesterdays date in ISO-8601 format:
DAY1=`date -I -d "1 day ago"`
#31 days ago in ISO-8601 format (to keep 30days backup)
DAY31=`date -I -d "31 days ago"`

#Rsync Process
rsync -e "$SSH -p $PORT" --rsync-path=$RSYNC -az --force --delete --ignore-errors --exclude-from=$EXCLUDES --delete-excluded --link-dest=../$DAY1 $SRC $HOST:$DST_DIR/$DAY0

#Cleaning backups older than 30 days
$SSH $HOST "if [ -d $DST_DIR/$DAY31 ];then rm -rf $DST_DIR/$DAY31;fi"

Comments

Popular posts from this blog

MySQL table conversion

Add addon-domain, sundomain and parked domains via shell in a Cpanel server

Cpanel Migration Script