RSYNC Upload Bash Script

Here’s a handy BSH script I use to upload files from my development server to the production server. Useful because it uses the –dry-run parameter as a default so you can easily make sure of what you’re going to break update before you actually do it.

#!/bin/bash
# dry run 
source_server=/some/source/folder/
destination_server=user@servername:/some/destination/folder
exclude_file=rsync-exclude-list.txt
clear
echo "Upload file to Production Server with Rsync"
echo "==============================================="
echo "Source: $source_server"
echo "Destination: $destination_server"
echo "Exclude: $exclude_file"
echo " "
read -r -p "Confirm Live Upload, press ENTER for --dry-run? [Y] " confirm

case $confirm in
	[yY] | [yY][eE][sS])
		dry_run=""
		 ;;
	*)
		dry_run="--dry-run"
		;;
esac

rsync -v -u -a -r $dry_run --rsh=ssh --stats --progress  --exclude-from $exclude_file "$source_server" "$destination_server"

Some things to note here. Firstly, if you don’t want to have to enter your password for the remote server every time you’ll have to generate a SSH key for your development server and add it to the accepted keys file on the live server. Second, make sure you put the trailing slash on the source_server variable. Third, make sure your user has the permissions required for the destination folder and for the sake of all that’s holy don’t be doing this with your root user.

This entry was posted in linux on by .

About markn

Mark is the owner and founder of Timesheets MTS Software, an mISV that develops and markets employee timesheet and time clock software. He's also a mechanical engineer, father of four, and a lifelong lover of gadgets.