LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] SOLVED: [Q] Transferring c.200GiB via net, preserving attributes... How?

[ILUG] SOLVED: [Q] Transferring c.200GiB via net, preserving attributes... How?

Brian Foster blf at utvinternet.ie
Fri Apr 6 10:33:49 IST 2012


 As an FYI, here is the script I'm using to do the transfer...
 It seems to work (do what I want) in tests, so now I'm trying
 the first “real” transfer.  Which is, of course, when problems
 will show up....  ;-\

──────────────────(cut here and below)──────────────────
#!/bin/bash

readonly  source=REDACTED		# Remote SOURCE machine
readonly    user=REDACTED		# Username on remote SOURCE
# Command on remote SOURCE which outputs the necessary
# password for superusership to stdout...
readonly askpass=REDACTED

opts=( )
dryrun=--dry-run
while [ $# -ge 1 ]; do
	case $1 in
	--)	shift; break			;;
	--Ok)	dryrun=""			;;
	-*)	opts=( "${opts[@]}" "$1" )	;;
	*)	break				;;
	esac
	shift
done
readonly opts dryrun

case $# in
2)	readonly srcdir="$1" dstdir="$2"
	;;
*)	echo >&2 -E "Usage: $0 [options]... [--] source_on_$source local_destination"
	exit 2
	;;
esac

# SOURCE paths ending with slash (`/') are suspicious,
# since that means (to rsync(1)) to _not_ create the
# directory on the DESTINATION.  In general, this is
# not what we want (mostly for safety, since `rsync'
# is run as the superuser (`root') on the DESTINATION,
# so we are paranoid about accidental overwrites!).
#
# For the same reason, we insist the DESTINATION path
# not (yet) exist.
#
[ -e "$dstdir" ] && {
	echo >&2 -E "$0: error 3: Destination \`$dstdir' exists!"
	exit 3
}
case $srcdir in
*/)	echo >&2 -E "$0: error 4: Source ends with \`/'?"
	exit 4
	;;
esac

# The SOURCE machine is (also) Ubuntu, meaning we "cannot" login
# as `root' (we, Ok, we _could_ enable such logins (or equivalent,
# such as using an SSH key), but....).  Since we must run rsync(1)
# on the SOURCE machine as the superuser, the trick is in how to
# run it using sudo(1) on the SOURCE.
#
# We cannot simply run `sudo rsync' (as the remote "rsync" program
# on the SOURCE machine) for a variety of reasons (not listed).
#
# The trick we use is to have a private, highly protected script
# on the SOURCE machine (the `/file/containing/password' is also,
# of course, highly protected):
#
#	cat </file/containing/password
#
# We then run that script as `sudo -A's "askpass" program.
# Easy!  ;-)
#
# This is (very loosely) based on the ideas presented in:
#    http://www.pplux.com/2009/02/07/rsync-root-and-sudo/

readonly authorise="SUDO_ASKPASS='$askpass' sudo -A --"
readonly   logfile="$(date -Imin)-${srcdir//\//,}"

readonly cmd=( rsync
	--human-readable --human-readable
	--progress
	--verbose
	--stats
	--log-file="$logfile"
	--rsync-path="$authorise rsync"
	--archive
	--hard-links
	--sparse
	--one-file-system
	--compress
	$dryrun
	"${opts[@]}" --
		$user@$source:$srcdir
		$dstdir
)
echo     -E "${cmd[@]}"  >>"$logfile"  ||  exit
echo >&2 -E "$0: rsync \`$srcdir' -> \`$dstdir' log=\`$logfile'"
\time --verbose --append --output="$logfile" -- sudo "${cmd[@]}"
sts=$?
sync
[ $sts -eq 0 ]  ||  echo >&2 -E "$0: rsync error $sts: \`$srcdir' -> \`$dstdir'"
sync
exit $sts
──────────────────(cut here and above)──────────────────

cheers!
	-blf-

-- 
“How many surrealists does it take to    |  Brian Foster
 change a lightbulb?  Three.  One calms  |  somewhere in south of France
 the warthog, and two fill the bathtub   |     Stop E$$o (ExxonMobil)!
 with brightly-coloured machine tools.”  |       http://www.stopesso.com


More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell