#!/bin/bash BACKUPDIR="/Users/YOURUSERNAME/Backups" BACKUPDIRDST="$BACKUPDIR/mywebsitebackups" BACKUPARCHIVES="$BACKUPDIR/archives" BACKUPLOGS="$BACKUPDIR/archive_logs" BACKUPDATE=$(date +"%Y-%d-%m%_H%M") BACKUPSRC="/path/to/your/website/directory/" BACKUPADDR="REMOTESERVERIP" BACKUPUSER="REMOTESSHUSERNAME" if [ ! -d "$BACKUPDIR" ]; then echo "Creating backups directory" mkdir -p $BACKUPDIRDST fi if [ ! -d "$BACKUPARCHIVES" ]; then echo "Creating backup archives directory" mkdir -p $BACKUPARCHIVES fi if [ ! -d "$BACKUPLOGS" ]; then echo "Creating backup archive logs directory" mkdir -p $BACKUPLOGS fi if [ ! -d "$BACKUPDIRDST" ]; then echo "Creating backup destination directory for storing downloaded files" mkdir -p $BACKUPDIRDST fi if [ -d "$BACKUPDIR" ]; then echo "Starting website backup at $BACKUPDATE" echo "Copying down new or changed files and directories" /usr/bin/rsync -acvi $BACKUPUSER@$BACKUPADDR:$BACKUPSRC $BACKUPDIRDST --stats --progress > $BACKUPLOGS/latestwebsitebackup_rsync_$BACKUPDATE.log cd $BACKUPDIR echo "Creating archive" /usr/bin/tar -cvf "$BACKUPARCHIVES/websitebackup_$BACKUPDATE.tar" $BACKUPDIRDST 2>> $BACKUPLOGS/latestwebsitebackup_archive_$BACKUPDATE.log echo "Compressing logs" /usr/bin/find $BACKUPLOGS -type f -iname "*.log" | /usr/bin/xargs /usr/bin/gzip -9 echo "Compressing archives" /usr/bin/find $BACKUPARCHIVES -type f -iname "*.tar" | /usr/bin/grep -v ".tar.gz" | /usr/bin/xargs /usr/bin/gzip -9 echo "Backup completed at $BACKUPDATE" fi