Created
September 4, 2018 05:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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