Skip to content

Instantly share code, notes, and snippets.

@cverbiest
Created September 4, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cverbiest/eb6aad6fc9b5b8524251aca25474d6ef to your computer and use it in GitHub Desktop.
Save cverbiest/eb6aad6fc9b5b8524251aca25474d6ef to your computer and use it in GitHub Desktop.
script to copy (rsync) files to new host, tool to help server migration
#!/bin/bash
set -ue
script=$0
script_dir=${script%/*}
script=${script##*/}
SUFFIX=$(date +%y%m%d.%H%M%S)
export RSYNC_RSH=/usr/bin/ssh
RSYNC_OPTS="--perms --owner --group --recursive --verbose --times --links"
# rsync options
# -pog Preserve permissions, owner, group
# -r recursive
# -v verbose or -q quiet
# -n dry run : show what would be transferred
SyncToNew()
{
file=$1
realfile=$(readlink -m "$file")
parent=$(dirname "$realfile")
echo rsync $RSYNC_OPTS "$realfile" "${USER}"@"${NEWHOST}":"$parent"
rsync $RSYNC_OPTS "$realfile" "${USER}"@"${NEWHOST}":"$parent" || echo "failed to sync $realfile" >&2 && echo "Synchronizing $realfile done"
}
for file in "$@"
do
SyncToNew "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment