Skip to content

Instantly share code, notes, and snippets.

@GaryLee
Created June 2, 2024 01:44
Show Gist options
  • Save GaryLee/fbf6a14cc7b0446c117ff12cfda1ec8a to your computer and use it in GitHub Desktop.
Save GaryLee/fbf6a14cc7b0446c117ff12cfda1ec8a to your computer and use it in GitHub Desktop.
A shell script what utilize rsync to backup import folders of desktop.
#!/bin/sh
# -delete flag will delete unmatched files and folder on target.
#DELETE_FLAG=-delete
DELETE_FLAG=
# The rsync flags
# -a, --archive
# This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost
# everything (with -H being a notable omission).
# -u, --update
# This forces rsync to skip any files which exist on the destination and have a modified time that is newer than
# the source file.
# -t, --times
# This tells rsync to transfer modification times along with the files and update them on the remote system.
# -C, --cvs-exclude
# This is a useful shorthand for excluding a broad range of files that you often don't want to transfer between
# systems. It uses the same algorithm that CVS uses to determine if a file should be ignored.
# -v, --verbose
# increase verbosit
SRC=~/Movies ~/Documents
DST=`dirname "$0"`/backup
EXCLUDE_FOLDER=--exclude='*/[cC]ache/'
for i in ${SRC}/*;
do
rsync -Cavut ${DELETE_FLAG} ${EXCLUDE_FOLDER} "$i" "$DST"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment