-
-
Save alem0lars/5774e630fab18f14c40b to your computer and use it in GitHub Desktop.
Perform filesystem migration to a destination server (via rsync)
This file contains hidden or 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
#!/usr/bin/env zsh | |
# parse arguments {{{ | |
zparseopts -A _opts -user: -dstsrv: -dstpath: | |
if [[ $? -ne 0 ]]; then | |
echo 'invalid arguments' | |
exit -1 | |
fi | |
_with_user=$([ -z "${(k)_opts[--user]}" ] && echo 0 || echo 1) | |
_user=${(v)_opts[--user]} | |
if [[ ${_with_user} -eq 0 ]]; then | |
echo 'you must provide a user' | |
exit -2 | |
fi | |
_with_dst_server=$([ -z "${(k)_opts[--dstsrv]}" ] && echo 0 || echo 1) | |
_dst_server=${(v)_opts[--dstsrv]} | |
if [[ ${_with_dst_server} -eq 0 ]]; then | |
echo 'you must provide a destination server' | |
exit -3 | |
fi | |
_with_dst_path=$([ ! -d "${(k)_opts[--dstpath]}" ] && echo 0 || echo 1) | |
_dst_path=${(v)_opts[--dstpath]} | |
if [[ ${_with_dst_path} -eq 0 ]]; then | |
echo 'you must provide a valid destination directory' | |
exit -4 | |
fi | |
# }}} | |
# perform rsync {{{ | |
rsync \ | |
--archive \ | |
--acls --executability --hard-links --xattrs --numeric-ids \ | |
--devices --specials \ | |
\ | |
--partial \ | |
--delete-delay --delete-excluded \ | |
\ | |
--compress \ | |
--sparse \ | |
\ | |
--human-readable --progress --verbose \ | |
\ | |
"/" "${_user}@${_dst_server}:${_dst_path}" \ | |
--exclude={"/dev/**","/proc/**","/sys/**","/tmp/**","/run/**","/mnt/**","/media/**","**/lost+found/**","/var/tmp/**"} | |
# }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment