rsync and deleted files

der.hans PLUGd at LuftHans.com
Tue Sep 8 09:57:08 MST 2009


Am 07. Sep, 2009 schwätzte Nathan England so:

moin moin Nathan,

> I plugged my USB drive into my system, ran my backup script and went to
> supper. My backup script contains
>
> rsync -avz --delete-after /home/naubrey/ /media/320GB/naubrey/
>
>
> Usually, it works great. Problem is my /home/naubrey/ directory on my
> system was EMPTY and it wiped out my backup!!!!

I suggest limiting this kind of damage.

--max-delete=NUM        don’t delete more than NUM files

> I just wiped my work laptop and reinstalled, but I had not copied my user
> directory stuff back because I needed to make some additional changes. I
> made the changes and wanted to back up the changes, forgetting my user
> directory was included in my all_inclusive backup script...
>
> The USB drive is ext2 and when I came back I immediately unmounted and
> mounted ro.

If you have space, made a dd copy of the partition that got wiped. Then,
if you've got space, make a copy of that image and try your recovery on
that copy. Then, if things get messed up you can make another copy and try
again. If you only have room for one copy of the image leave the USB drive
as read-only and work on the copy. If the copy gets messed up you can make
a pristine copy again.

cp -p is faster than dd and local bus should be much faster than USB,
which is why I suggest working on a copy of the copy.

# If the USB partition is /dev/sdb1 and the free space is in
# /mnt/bigspace, then the following commands should do what you need.
* It's been a long time since I looked at recover, so you'll have to
# figure that one out.

# Check that you understand each of the commands before running them! :)

dd if=/dev/sdb1 of=/mnt/bigspace/usb_drive.2009Spe08.img

cp -p /mnt/bigspace/usb_drive.2009Spe08.img \
 	/mnt/bigspace/usb_drive-copy.2009Spe08.img

sudo mkdir /mnt/usb_recover

sudo mount -o loop /mnt/bigspace/usb_drive-copy.2009Spe08.img /mnt/usb_recover

recover -options /mnt/usb_recover

> This is a typical user directory with 60GB of text files, abiword files,
> kword files, OpenOffice files, mp3, ogg, about 100 avi dvds, and thousands
> of notes... Some files were only 2 k others were over 1GB.
>
> As I have never attempted recovery of deleted files because I am (99% of
> the time) very vigilante about my backups. I design backup systems for
> customers!!!! ha ha

Not having space will be a problem. Can you borrow a drive from someone?
Do you know a place with a GB free that will let you boot off a USB thumb
drive?

> What utilities or programs are there that might automate this as I really
> don't care to sit and tell the system to recover this inode, and yes, this
> inode, and again y to this inode as there are well over 200,000 files.

recover will toss all the files in a directory for you or something.

For the future you might wish to allow some extra space for backups and
using something like BackupPC. It can use rsync and it uses a hard link
farm in order to only keep one copy of a version of a file no matter how
many times it's backed up. I find it doesn't actually use much more space.
If you have lots of text files BackupPC might use less space because it
transparently compresses files in the backup area.

Also, check the archives for file recovery threads. Other people have made
good suggestions in the past.

ciao,

der.hans
-- 
#  http://www.LuftHans.com/        http://www.ABLEconf.com/
#  Director of Engineering, FonWallet Transaction Solutions, Inc.
#  ABLEconf: Saturday, 2009Okt24, Tempe. Call for Presentations now open.
#  Your email is being read by hundreds of uptight agents
#  who never saw the humor in Dr. Strangelove. -- Mark Russell


More information about the PLUG-discuss mailing list