Skip to content

Instantly share code, notes, and snippets.

@LMolr
Last active December 18, 2015 20:29
Show Gist options
  • Save LMolr/5840390 to your computer and use it in GitHub Desktop.
Save LMolr/5840390 to your computer and use it in GitHub Desktop.
gentoo rsync full drive migration
#!/usr/bin/env zsh
# Authors: alem0lars, LMolr
# 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