Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##### Script to sync / backup my media downloads to a USB hard drive
- ##### 2016 Jeremy Sparks
- clear
- datevar=$( date +%r )
- echo
- echo "Filesync script started at"$datevar" by user: "$USER""
- ##### Performs a dry run of the rsync commands using a separate BASH script and counts the lines of output.
- ##### If this output is more than 50 then there must be files to transfer.
- dryrun=$( ./filesync/dry-run.sh | wc -l )
- if [ $dryrun -le 50 ]; then
- printf "\nAll files are already synced and up to date.\n\n"
- ##### Prompts user for input.
- else
- printf "\n\nPlease select from the following file types to sync:\n"
- printf "\n--- documents\n--- scripts\n--- pictures\n--- music\n--- videos\n--- downloads\n--- all\n"
- printf "\nType documents, scripts, pictures, music, videos, downloads or all:\n\n"
- ##### This script also takes input from command line using an "all" flag (useful for running on a Crontab job).
- if [ $# -lt 1 ]; then
- read input
- case $input in
- ##### Runs rsync to sync everything from the USB HDD to the PC, then the other way.
- ##### Files will be updated if they are larger in file size but timestamps are ignored (with the exception of documents and scripts).
- documents)
- printf "\nDocuments option selected\n\n"
- rsync -havp --progress --update /media/jeremy/SAMSUNG/Documents/ /home/jeremy/Documents/
- rsync -havp --progress --update /home/jeremy/Documents/ /media/jeremy/SAMSUNG/Documents/
- ;;
- scripts)
- printf "\bScripts option selected\n\n"
- rsync -havp --progress --update /media/jeremy/SAMSUNG/bin/ /home/jeremy/bin/
- rsync -havp --progress --update /home/jeremy/bin/ /media/jeremy/SAMSUNG/bin/
- ;;
- pictures)
- printf "\nPictures option selected\n\n"
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Pictures/ /home/jeremy/Pictures/
- rsync -havp --progress --size-only /home/jeremy/Pictures/ /media/jeremy/SAMSUNG/Pictures/
- ;;
- music)
- printf "\nMusic option selected\n\n"
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Music/ /home/jeremy/Music/
- rsync -havp --progress --size-only /home/jeremy/Music/ /media/jeremy/SAMSUNG/Music/
- ;;
- videos)
- printf "\nVideos option selected\n\n"
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Videos/ /home/jeremy/Videos/
- rsync -havp --progress --size-only /home/jeremy/Videos/ /media/jeremy/SAMSUNG/Videos/
- ;;
- downloads)
- printf "\nDownloads option selected\n\n"
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Downloads/ /home/jeremy/Downloads/
- rsync -havp --progress --size-only /home/jeremy/Downloads/ /media/jeremy/SAMSUNG/Downloads/
- ;;
- all)
- printf "\nSync all option selected\n\n"
- rsync -havp --progress --update /media/jeremy/SAMSUNG/Documents/ /home/jeremy/Documents/
- rsync -havp --progress --update /home/jeremy/Documents/ /media/jeremy/SAMSUNG/Documents/
- rsync -havp --progress --update /media/jeremy/SAMSUNG/bin/ /home/jeremy/bin/
- rsync -havp --progress --update /home/jeremy/bin/ /media/jeremy/SAMSUNG/bin/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Pictures/ /home/jeremy/Pictures/
- rsync -havp --progress --size-only /home/jeremy/Pictures/ /media/jeremy/SAMSUNG/Pictures/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Music/ /home/jeremy/Music/
- rsync -havp --progress --size-only /home/jeremy/Music/ /media/jeremy/SAMSUNG/Music/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Videos/ /home/jeremy/Videos/
- rsync -havp --progress --size-only /home/jeremy/Videos/ /media/jeremy/SAMSUNG/Videos/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Downloads/ /home/jeremy/Downloads/
- rsync -havp --progress --size-only /home/jeremy/Downloads/ /media/jeremy/SAMSUNG/Downloads/
- ;;
- *)
- printf "\nSorry, your input was not recognised.\n\n"
- ;;
- esac
- printf "\nThank you. Your file sync has been completed.\n\n"
- exit 0
- else
- ##### Code to run if the "all" argument is passed from the command line.
- case "$1" in
- all)
- rsync -havp --progress --update /media/jeremy/SAMSUNG/Documents/ /home/jeremy/Documents/
- rsync -havp --progress --update /home/jeremy/Documents/ /media/jeremy/SAMSUNG/Documents/
- rsync -havp --progress --update /media/jeremy/SAMSUNG/bin/ /home/jeremy/bin/
- rsync -havp --progress --update /home/jeremy/bin/ /media/jeremy/SAMSUNG/bin/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Pictures/ /home/jeremy/Pictures/
- rsync -havp --progress --size-only /home/jeremy/Pictures/ /media/jeremy/SAMSUNG/Pictures/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Music/ /home/jeremy/Music/
- rsync -havp --progress --size-only /home/jeremy/Music/ /media/jeremy/SAMSUNG/Music/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Videos/ /home/jeremy/Videos/
- rsync -havp --progress --size-only /home/jeremy/Videos/ /media/jeremy/SAMSUNG/Videos/
- rsync -havp --progress --size-only /media/jeremy/SAMSUNG/Downloads/ /home/jeremy/Downloads/
- rsync -havp --progress --size-only /home/jeremy/Downloads/ /media/jeremy/SAMSUNG/Downloads/
- ;;
- esac
- printf "\nThank you. Your file sync has been completed.\n\n"
- fi
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement