Skip to content

Instantly share code, notes, and snippets.

@senorsmile
Last active January 15, 2017 20:32
Show Gist options
  • Select an option

  • Save senorsmile/601479c68d9ab1c7518b0a8106db4ea3 to your computer and use it in GitHub Desktop.

Select an option

Save senorsmile/601479c68d9ab1c7518b0a8106db4ea3 to your computer and use it in GitHub Desktop.
add message if rsync already running
#!/usr/bin/env bash
#--------
# ALL dirs must end with a backslash
#--------
now=$(date +%Y-%m-%d_%H:%M:%S_%N)
src='/home/shaun/'
dest_url='127.0.0.1'
dest_dir='/home/shaun/rsync_backups/'
dest_username='shaun'
src_dirs=(
Downloads/
Desktop/
)
[[ $(ps aux | grep [r]sync) ]] && {
echo "rsync already running. Exiting..."
} || { #only run if rsync process not already running
for dir in "${src_dirs[@]}"; do
/usr/bin/rsync -avzP "${src}${dir}" "${dest_username}@${dest_url}:${dest_dir}" &>"/var/log/backups_${now}"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment