Mailinglist Archive: opensuse (2806 mails)
| < Previous | Next > |
Re: [opensuse] Rsync question
- From: Bob Williams <linux@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 29 Jul 2008 19:43:10 +0100
- Message-id: <200807291943.11908.linux@xxxxxxxxxxxxxxxxxxxxx>
On Monday 28 July 2008 13:38:12 Carlos E. R. wrote:
This is the script I have used for several years. It works well, and is
based on Mike Rubel's script. I believe things like rsnapshot are gui
frontends for something similar. The incremental functionality comes from
cp being able to make hardlinks to files, so even though rsync has
deleted a file in today's backup, the file still exists because there is
a hardlink in yesterday's copy. The file is lost only when the hardlink
falls off the end (in my case, after 28 days). The script runs as a
nightly cronjob by root. 'lacie' is the name of my external USB backup
drive.
----------------
#!/bin/bash
# step 1: delete the oldest snapshot, if it exists
if [ -d /media/lacie/daily.28 ] ; then rm -rf /media/lacie/daily.28 ; fi ;
# step 2: shift the middle snapshot(s) back by one, if they exist
if [ -d /media/lacie/daily.27 ] ; then
mv /media/lacie/daily.27 /media/lacie/daily.28 ; fi ;
if [ -d /media/lacie/daily.26 ] ; then
mv /media/lacie/daily.26 /media/lacie/daily.27 ; fi ;
if [ -d /media/lacie/daily.25 ] ; then
mv /media/lacie/daily.25 /media/lacie/daily.26 ; fi ;
if [ -d /media/lacie/daily.24 ] ; then
mv /media/lacie/daily.24 /media/lacie/daily.25 ; fi ;
if [ -d /media/lacie/daily.23 ] ; then
mv /media/lacie/daily.23 /media/lacie/daily.24 ; fi ;
if [ -d /media/lacie/daily.22 ] ; then
mv /media/lacie/daily.22 /media/lacie/daily.23 ; fi ;
if [ -d /media/lacie/daily.21 ] ; then
mv /media/lacie/daily.21 /media/lacie/daily.22 ; fi ;
if [ -d /media/lacie/daily.20 ] ; then
mv /media/lacie/daily.20 /media/lacie/daily.21 ; fi ;
if [ -d /media/lacie/daily.19 ] ; then
mv /media/lacie/daily.19 /media/lacie/daily.20 ; fi ;
if [ -d /media/lacie/daily.18 ] ; then
mv /media/lacie/daily.18 /media/lacie/daily.19 ; fi ;
if [ -d /media/lacie/daily.17 ] ; then
mv /media/lacie/daily.17 /media/lacie/daily.18 ; fi ;
if [ -d /media/lacie/daily.16 ] ; then
mv /media/lacie/daily.16 /media/lacie/daily.17 ; fi ;
if [ -d /media/lacie/daily.15 ] ; then
mv /media/lacie/daily.15 /media/lacie/daily.16 ; fi ;
if [ -d /media/lacie/daily.14 ] ; then
mv /media/lacie/daily.14 /media/lacie/daily.15 ; fi ;
if [ -d /media/lacie/daily.13 ] ; then
mv /media/lacie/daily.13 /media/lacie/daily.14 ; fi ;
if [ -d /media/lacie/daily.12 ] ; then
mv /media/lacie/daily.12 /media/lacie/daily.13 ; fi ;
if [ -d /media/lacie/daily.11 ] ; then
mv /media/lacie/daily.11 /media/lacie/daily.12 ; fi ;
if [ -d /media/lacie/daily.10 ] ; then
mv /media/lacie/daily.10 /media/lacie/daily.11 ; fi ;
if [ -d /media/lacie/daily.09 ] ; then
mv /media/lacie/daily.09 /media/lacie/daily.10 ; fi ;
if [ -d /media/lacie/daily.08 ] ; then
mv /media/lacie/daily.08 /media/lacie/daily.09 ; fi ;
if [ -d /media/lacie/daily.07 ] ; then
mv /media/lacie/daily.07 /media/lacie/daily.08 ; fi ;
if [ -d /media/lacie/daily.06 ] ; then
mv /media/lacie/daily.06 /media/lacie/daily.07 ; fi ;
if [ -d /media/lacie/daily.05 ] ; then
mv /media/lacie/daily.05 /media/lacie/daily.06 ; fi ;
if [ -d /media/lacie/daily.04 ] ; then
mv /media/lacie/daily.04 /media/lacie/daily.05 ; fi ;
if [ -d /media/lacie/daily.03 ] ; then
mv /media/lacie/daily.03 /media/lacie/daily.04 ; fi ;
if [ -d /media/lacie/daily.02 ] ; then
mv /media/lacie/daily.02 /media/lacie/daily.03 ; fi ;
if [ -d /media/lacie/daily.01 ] ; then
mv /media/lacie/daily.01 /media/lacie/daily.02 ; fi ;
# step 3: make a hard-link-only (except for dirs) copy of the latest
snapshot.
# if that exists
if [ -d /media/lacie/daily.00 ] ; then
cp -al /media/lacie/daily.00 /media/lacie/daily.01 ; fi ;
# step 4: rsync from the system into the latest snapshot
# - this is the bit that does the actual backup!
/usr/bin/rsync -av --no-l --delete --delete-excluded
--exclude-from=/home/bob/bin/excludedfiles /etc /home/bob /home/hils /home/leon
/home/play /home/Shared_Documents /media/lacie/daily.00
----------------
--
Bob
Registered Linux User #463880 FSFE Member #1300
GPG-FP: A6C1 457C 6DBA B13E 5524 F703 D12A FB79 926B 994E
openSUSE 11.0, Kernel 2.6.25.11-0.1-default, KDE 3.5.9
Intel Celeron 2.53GB, 2GB DDR RAM, nVidia GeForce 7600GS
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
The Monday 2008-07-28 at 14:09 +0200, J Beris wrote:
I have a question about Rsync. Like several people here, I use an
external USB disk to make daily backups of my critical data. For
this, I have written a shell script which mounts the disk as
necessary and then calls rsync to do the actual backup.
This works very well, except that if I delete a file in my home
directory, have rsync do its thing at night, then the next morning
that deleted file is gone from my backup too, so I can only go back
one day. This is nice for a disk crash, but not for restoring data
that was deleted 4 days ago, for instance. Can someone tell me if it
is possible to have rsync retain the data in the backup for say
another 14 or 30 days before purging them? I have looked at the man
page, but haven't found an answer to my question there. Does someone
have an idea, please?
rsync $OPTIONS --link-dest=$YESTERDAY $WHAT $TODAY
But it would probably be easier to use any of the several existing
scripts that handle that situation nicely.
rdiff-backup the previous backups are stored as rdifs.
I think it will go very slow over USB.
rsnapshot rsync style.
http://www.dirvish.org/
pdumpfs (http://0xcc.net/pdumpfs)
--
Cheers,
Carlos E. R.
This is the script I have used for several years. It works well, and is
based on Mike Rubel's script. I believe things like rsnapshot are gui
frontends for something similar. The incremental functionality comes from
cp being able to make hardlinks to files, so even though rsync has
deleted a file in today's backup, the file still exists because there is
a hardlink in yesterday's copy. The file is lost only when the hardlink
falls off the end (in my case, after 28 days). The script runs as a
nightly cronjob by root. 'lacie' is the name of my external USB backup
drive.
----------------
#!/bin/bash
# step 1: delete the oldest snapshot, if it exists
if [ -d /media/lacie/daily.28 ] ; then rm -rf /media/lacie/daily.28 ; fi ;
# step 2: shift the middle snapshot(s) back by one, if they exist
if [ -d /media/lacie/daily.27 ] ; then
mv /media/lacie/daily.27 /media/lacie/daily.28 ; fi ;
if [ -d /media/lacie/daily.26 ] ; then
mv /media/lacie/daily.26 /media/lacie/daily.27 ; fi ;
if [ -d /media/lacie/daily.25 ] ; then
mv /media/lacie/daily.25 /media/lacie/daily.26 ; fi ;
if [ -d /media/lacie/daily.24 ] ; then
mv /media/lacie/daily.24 /media/lacie/daily.25 ; fi ;
if [ -d /media/lacie/daily.23 ] ; then
mv /media/lacie/daily.23 /media/lacie/daily.24 ; fi ;
if [ -d /media/lacie/daily.22 ] ; then
mv /media/lacie/daily.22 /media/lacie/daily.23 ; fi ;
if [ -d /media/lacie/daily.21 ] ; then
mv /media/lacie/daily.21 /media/lacie/daily.22 ; fi ;
if [ -d /media/lacie/daily.20 ] ; then
mv /media/lacie/daily.20 /media/lacie/daily.21 ; fi ;
if [ -d /media/lacie/daily.19 ] ; then
mv /media/lacie/daily.19 /media/lacie/daily.20 ; fi ;
if [ -d /media/lacie/daily.18 ] ; then
mv /media/lacie/daily.18 /media/lacie/daily.19 ; fi ;
if [ -d /media/lacie/daily.17 ] ; then
mv /media/lacie/daily.17 /media/lacie/daily.18 ; fi ;
if [ -d /media/lacie/daily.16 ] ; then
mv /media/lacie/daily.16 /media/lacie/daily.17 ; fi ;
if [ -d /media/lacie/daily.15 ] ; then
mv /media/lacie/daily.15 /media/lacie/daily.16 ; fi ;
if [ -d /media/lacie/daily.14 ] ; then
mv /media/lacie/daily.14 /media/lacie/daily.15 ; fi ;
if [ -d /media/lacie/daily.13 ] ; then
mv /media/lacie/daily.13 /media/lacie/daily.14 ; fi ;
if [ -d /media/lacie/daily.12 ] ; then
mv /media/lacie/daily.12 /media/lacie/daily.13 ; fi ;
if [ -d /media/lacie/daily.11 ] ; then
mv /media/lacie/daily.11 /media/lacie/daily.12 ; fi ;
if [ -d /media/lacie/daily.10 ] ; then
mv /media/lacie/daily.10 /media/lacie/daily.11 ; fi ;
if [ -d /media/lacie/daily.09 ] ; then
mv /media/lacie/daily.09 /media/lacie/daily.10 ; fi ;
if [ -d /media/lacie/daily.08 ] ; then
mv /media/lacie/daily.08 /media/lacie/daily.09 ; fi ;
if [ -d /media/lacie/daily.07 ] ; then
mv /media/lacie/daily.07 /media/lacie/daily.08 ; fi ;
if [ -d /media/lacie/daily.06 ] ; then
mv /media/lacie/daily.06 /media/lacie/daily.07 ; fi ;
if [ -d /media/lacie/daily.05 ] ; then
mv /media/lacie/daily.05 /media/lacie/daily.06 ; fi ;
if [ -d /media/lacie/daily.04 ] ; then
mv /media/lacie/daily.04 /media/lacie/daily.05 ; fi ;
if [ -d /media/lacie/daily.03 ] ; then
mv /media/lacie/daily.03 /media/lacie/daily.04 ; fi ;
if [ -d /media/lacie/daily.02 ] ; then
mv /media/lacie/daily.02 /media/lacie/daily.03 ; fi ;
if [ -d /media/lacie/daily.01 ] ; then
mv /media/lacie/daily.01 /media/lacie/daily.02 ; fi ;
# step 3: make a hard-link-only (except for dirs) copy of the latest
snapshot.
# if that exists
if [ -d /media/lacie/daily.00 ] ; then
cp -al /media/lacie/daily.00 /media/lacie/daily.01 ; fi ;
# step 4: rsync from the system into the latest snapshot
# - this is the bit that does the actual backup!
/usr/bin/rsync -av --no-l --delete --delete-excluded
--exclude-from=/home/bob/bin/excludedfiles /etc /home/bob /home/hils /home/leon
/home/play /home/Shared_Documents /media/lacie/daily.00
----------------
--
Bob
Registered Linux User #463880 FSFE Member #1300
GPG-FP: A6C1 457C 6DBA B13E 5524 F703 D12A FB79 926B 994E
openSUSE 11.0, Kernel 2.6.25.11-0.1-default, KDE 3.5.9
Intel Celeron 2.53GB, 2GB DDR RAM, nVidia GeForce 7600GS
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
| < Previous | Next > |