Forum

Full Version: Can i use the "btrfs-auto-snapshot xbiancopy" cli to restore an img file?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to restore an img file to an usb drive. The img file is much bigger then the usb drive, although the content should fit.

How do I do this? I'd like to do this from the RaspPi via ssh if possible.

The btrfs file system is new to me. When I mounted the img file I noted that things were saved in /@/ folders. So I assume that just copying things over to a the brfs partition on the usb drive would not work.

I tried using the xbiancopy via the cli but "btrfs-auto-snapshot xbiancopy -h" doesn't offer much in terms of documentation.
@TheBigD

btrfs-auto-snapshot has no support for restoring .img as this .img file is simply a blockdevice byte copy. normally, you would dd it back block device.

the size of created .img file is "used data at the time copy was taken" + 300MB.

the only difference you see comparing to other filesystems are the subvolumes (root, home, modules ...) you see. otherwise it is just filesystem as all others. if you are interested on system files, copy from "root/@". if you are interested in home (XBMC files, xbian user) then go for "home/@"

(always remember to copy ownership and mode file !!! when copying).
Ok, so copying the files should work. Do i need to recreate the sub volumes on the target partiton? Like this?

Terminal
sudo -i

#mount img file after using parted to see offset
mount -o loop,ro,offset=36700160 /media/path/xbianBU140125/xbian.img /media/imgf

#format and mount usb stick to be used for system
umount /dev/sda2
mkfs.btrfs -L xbian-usb /dev/sda2
mount /dev/sda2 /mnt

cd /mnt

#create subvolumes?
btrfs subvolume create root
btrfs subvolume create home
btrfs subvolume create modules
btrfs subvolume create data

#copy files
rsync -aAX /media/imgf/root/@/* /mnt/root/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs} --progress

rsync -aAX /media/imgf/home/@/* /mnt/home/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs} --progress

rsync -aAX /media/imgf/modules/@/* /mnt/modules/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs} --progress

rsync -aAX /media/imgf/data/@/* /mnt/data/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs} --progress
oh, ok, ... forget all above and ...

yes, you can extract .img file to a partition. you have to map the .img with partition layout and use xbiancopy function from command line with speecifiing source different than default /dev/root:

Code:
sudo -i
modprobe loop
kpartx -av /path/to/my.img
btrfs-auto-snapshot xbiancopy /dev/mapper/loop0p2 /dev/sdXXXX
kpartx -dv /path/to/my.img

depending on kernel package version installed on .img and actual on /boot, after system boots reinstall kernel package if needed
Code:
apt-get install xbian-package-kernel

if you get error already installed

apt-get install --reinstall xbian-package-kernel

or second option is to take the /boot from img file (/dev/mapper/loop0p1) and copy to /boot
Excellent! I haven't got it all up and running yet, but it seems that there is stuff on the usb stick now, so it looks promising.

Thanks!
Just a follow up. Everything is up and running from the USB, as it should. I'll try to change the heading to reflect that.

My img files do not seem to be "the size of created .img file is "used data at the time copy was taken" + 300MB. " however. They seem to be the size of a raw copy to me.
@TheBigD

"rawcopy" size ( -x00MB to allow flash if another card is used - same sized cards could have some minor differences) was used in very first version of this function.

I can't tell when exactly it was enhanced but it was already a while back.
Reference URL's