Mailinglist Archive: opensuse (3513 mails)

< Previous Next >
Re: [opensuse] rsync ?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Thu, 08 Jan 2009 15:59:53 -0600
  • Message-id: <49667759.6020300@xxxxxxxxxxxxxxxxxx>
Greg Freemyer wrote:
On Thu, Jan 8, 2009 at 12:31 PM, Erik Jakobsen <eja@xxxxxxxxxxx> wrote:
Greg Freemyer wrote:
Many thanks for the replies to my query.
Not that I understand much of it, but I will study the man page, and hope
I get more insight.

If you found this confusing, avoid the daemon mode unless you
absolutely need it.

Are you trying to rsync between 2 directories on one computer, or
between 2 computers?

If 2:

Can you ssh between the 2 machines?

Is rsync installed on both machines?


Thank you very much Greg.

I have a HDD with backup from a NAS server done via USB HDD.

If the backup was made by rsync, then the backup is just a simple copy
of the data being backed up.

The directory structure should be in place.

rsync is basically just a directory tree copy tool that has
optimizations to copy only changes if possible.

So if you are copying a 10 MB file between 2 computers and 9.5 MB is
the same as it was the last time you ran rsync, then rsync will
compare the old copy to the new copy and just copy over the .5 MB of

The key thing to understand is that when rsync is done the source and
the destination should be identical.

I want to restore the backup on another NAS server, and it also has USB
on it.

And yes I can ssh and rsync is installed on the NAS server.

So this is in a way a rsync between 2 directories.

If the data on the USB drive is just a rsync'ed copy of the original
you don't even have to use rsync to restore it. (but you can easily

Just plug the USB drive into the computer you want to restore to.

It should automount in the /media directory.

Use a file browser (Konqueror or Dolphin) to go the /media folder and
see if you see the USB drive.

Then open that folder and you should see the files that were backed up.

Then just use the file browser to make a copy on the server wherever
it is you want them.



Also, in my example I left out the machine-to-machine copying that you
talking about. That is what rsync was made for. Take for example 2 machines on
my local lan that I want to backup files between. The normal form of rsync for
this purpose is:

rsync user@machine1:/path/to/src/files user@machine2:/path/to/destination

Taking a real world example, my laptop is 'alchemy' and my server is
'nirvana'. I routinely download pictures from my family's digital cameras to my
laptop and then rsync them to my server for permanent keeping. On my laptop I
download the pictures to /home/david/pictures/family/20090108-deb or
/home/david/pictures/family/20090108-sydney for example depending on whose
camera they came from.

On the server nirvana, all the pictures are stored in their original
directories under /home/samba/pictures/family_pictures/year2009/ for example.
After downloading new pictures to my laptop, I just call rsync with the same
source and destination locations and it takes care of the rest:

rsync -rtv david@alchemy:/home/david/pictures/family/

I also backup the data from my law office across the internet each
night using
rsync and ssh. I use ssh keys for authentication so no password is needed
allowing rsync to be run from a cron job. For remote rsync use, all you need to
do is specify -e ssh as an option to tell rsync to use ssh as the shell. The
remote backups go like this:

rsync -arze ssh --delete
david@xxxxxxxxxx:/home/samba/ /home/samba/law

The workfiles are:

# cat workfiles

I have the calls in a script that also give me a daily report of
whether the
backup succeeded or failed:

if /usr/bin/rsync -arze ssh --delete
david@xxxxxxxxxx:/home/samba/ /home/samba/law
echo .... Rankin Law Firm backup ------------- [OK] >> $LOGFILE
echo .... Rankin Law Firm backup ------------- [Failed] >> $LOGFILE

I also backup the mail and websites with 2 more rsync calls. That keeps
duplicate copy of my working files offsite at my home server as well as at work
(In case the building burns, etc...) Spend 2 hours learning rsync and it will
save you hundreds in the future. The scripting possibilities are endless. I
wrote a generic little rsync backup that reads the source, destination and
options from a single file and performs the backups accordingly.

I'll include it here just for an example:

#!/bin/bash --norc
## This rsyncs the files specified in /home/backup/.data/rsfiles to this server
## Check to make sure the script is run as root

if [ "$UID" -ne "$ROOT_UID" ]; then
echo -e "\nYou must be root to run this script.\nUser: $USER, UID: $UID
can't! See below...\n"


[[ -d $LOGDIR ]] || { sudo mkdir -p /home/backup/log; sudo chown david:dcr
[[ -d $LOGDIR ]] || { echo -e "\n\tUnable to Create $LOGDIR\n"; exit 1; }
[[ -r $SRVFILES ]] || { echo -e "\n\t$SRVFILES unreadable\n"; exit 1; }
[[ -e $LOGZIPFILE ]] && bunzip2 --force $LOGZIPFILE

#while [[ $# -gt 0 ]]; do

case "$1" in
-v|--verbose ) VERBOSE=1; echo -e "\ncase -v | --verbose
activated: VERBOSE=${VERBOSE}" ;;
-t|--test ) VERBOSE=2; echo -e "\ncase -t | --test activated:

[[ ! $1 ]] && VERBOSE=0
# shift

## Begin rsync
echo "$(date '+%b %e %T') ${0##*/} ---------- backup to $HOSTNAME started
----------" >> $LOGFILE

{ while read OPT SRC DEST; do
# check for comment lines
if [[ ${OPT} =~ ['#'';'] ]]; then
# echo "\${OPT} contains a comment: ${OPT}"
# provide verbose output if cli agrument given
case ${VERBOSE} in
0 )
if rsync ${OPT} ${SRC} ${DEST} >> /dev/null 2>&1; then
echo "$(date '+%b %e %T') ${0##*/} rsync of
${SRC} to ${DEST} Succeeded" >> $LOGFILE
echo "$(date '+%b %e %T') ${0##*/} rsync of
1 )
echo -e "\nOPT = ${OPT}; SRC = ${SRC}; DEST = ${DEST}"
echo -e "CLI = rsync ${OPT} ${SRC} ${DEST}"
if rsync ${OPT} ${SRC} ${DEST} >> $LOGFILE 2>&1; then
echo -e "rsync of ${SRC}\t\tSucceeded"
echo "$(date '+%b %e %T') ${0##*/} rsync of
${SRC} to ${DEST} Succeeded" >> $LOGFILE
echo -e "rsync of ${SRC}\t\tFailed!"
echo "$(date '+%b %e %T') ${0##*/} rsync of
2 )
echo -e "\nOPT = ${OPT}; SRC = ${SRC}; DEST = ${DEST}"
echo -e "CLI = rsync ${OPT} ${SRC} ${DEST}";;
* ) echo -e "\n\tUsage: ${0##*/} [ -t print file list and
exit, -v verbose ]\n"
exit 1;;

done } < "$SRVFILES"

# echo "$(date '+%b %e %T') ${0##*/} ---------- backup to $HOSTNAME complete
----------" >> $LOGFILE
bzip2 $LOGFILE

exit 0

Where the data file 'rsfiles' is:

[15:55 ecstasy/usr/local/bin] # cat /home/backup/.data/rsfiles
## Datafile for the rsync script. Each line below is formatted as:
## rsync options source file location destination
-av\ --delete david@nirvana:/home/samba/skyline /home/samba
## www files and directories
-av david@nirvana:/srv/www/css /srv/www
-av david@nirvana:/srv/www/dcr /srv/www
-av david@nirvana:/srv/www/gd /srv/www
-av david@nirvana:/srv/www/icons /srv/www
-av david@nirvana:/srv/www/images /srv/www
-av david@nirvana:/srv/www/js /srv/www
-av david@nirvana:/srv/www/skyline-live.session /srv/www/ecstasy-live.session
-av david@nirvana:/srv/www/skyline-live.webprj /srv/www/ecstasy-live.webprj
-av david@nirvana:/srv/www/templates /srv/www
-av david@nirvana:/srv/www/toolbars /srv/www
-av david@nirvana:/srv/www/vhosts /srv/www
## website content files and directories
-av david@nirvana:/srv/www/htdocs/linux /srv/www/htdocs
-av david@nirvana:/srv/www/htdocs/law/license /srv/www/htdocs/law
-av david@nirvana:/srv/www/htdocs/**.php /srv/www/htdocs
-av david@nirvana:/srv/www/htdocs/favicon.ico /srv/www/htdocs
-av david@nirvana:/srv/www/tmp/skyline /srv/www/tmp

Now you know as much about rsync as I do. Have fun....

David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >