rootfs.tar.bz2 generation


hmc

Active Member
Joined
Dec 19, 2011
Messages
787
Location
Bavaria, Germany
Hi guys,


I'd like to write a bash script, which backs up my Pandora to an external hard drive, so that I can later restore the entire Pandora system from that backup easily.


After three times making a small mistake with some commands, resulting in either complete or partial destroyed root file systems ;-) (and since this is very annoying for me, because I apply a lot of modifications to the default system for optimization) I think it's time now to implement a good backup script.


What's already working is the rsync part, which incrementally backs up the FAT partition of my boot SD card.


Now I'd need a suitable tar command, which generates a tarball of the rootfs.


I'd like to have, as the result, a tarball which can be used in place of the pandora-rootfs.tar.bz2 file when generating a new bootable SD card.


What I currently do is



Code:
tar cfjv "$DESTINATION"/SD_ROOT.tar.bz2 /etc /usr /bin /home /pandora /sbin /var /boot /lib 2>&1 | tee backup.log



I suspect I need to tar the entire root fs, but is it a good way to simply to a







Code:
tar cfjv "$DESTINATION"/pandora-rootfs-backup.tar.bz2 / 2>&1 | tee backup.log


?


Won't there be problems with accessing the /dev/* nodes and other nasty things?


However, the original pandora-rootfs.tar.bz2 seems to contain those things ...


Thanks,


Daniel
 
If I were you I'd make another mount of rootfs somewhere else or do it not on a live system, i.e. boot from SD (later is preferred). Then you just tar everything, run it with root user of course to get all files read.
 
Last edited by a moderator:
I agree with notaz.


When i backup my root-SD-card, then i boot from NAND, put the root-SD-card into mass-storage-mode and tar.gz the complete SD-card from my linux-PC. If you got a separate card-reader, then you can use that of course instead of using mass-storage-mode. Once mounted i would do:



Code:
cd /media/<sdcard>/

tar czf /<backup-dir>/pandora-root-2012-01-02 . --one-file-system

"--one-file-system" is probably not needed, but it became a habit of mine. Restoring would be





Code:
cd /media/<sdcard>/

tar xzf /<backup-dir>/pandora-root-2012-01-02 . --numeric-owner


However i only got one ext2-partition on my boot-SD-card (beside swap). Why does yours have a fat-partition? In order to access it from a windows-PC? If that means that your main-PC runs windows, then the above won't work as easily. You could still boot from NAND and backup to a FAT32-card/USB-HDD or with a few tricks over network.
 
Last edited by a moderator:
Thanks for your comments.


Mine has a FAT partition for easy access from a Mac. And on Mac, tar is available.


However, Mac doesn't have ExtFS support natively.


I'd need to install an ext2/ext3 driver, but it seems that all available (non-commercial) options for this are unstable or obsolete.


Actually, I'd prefer to do it all on the Pandora anyway, not involving any other machine (I am always trying to make the mobile computer I mainly use, which now is the Pandora, an independent mini PC)


Also, I would prefer not having to bot from NAND for backing up the SD root fs.


I think what I will do is the following:


(thanks for the --numeric-owner reminder, however, I have added it to the backup tar command, then it's not needed for restoring anymore)

Code:

#!/bin/bash


DEST="/media/sda1/BackupPandora"


BEGIN=`date`


#backup BOOT (FAT partition of SD card)


rsync -v -a --modify-window=2 -x --delete-before --stats -h --progress --partial-dir=.rsync-partial --ignore-errors /media/BOOT/ "$DEST"/SD_BOOT/ 2>&1 | tee /tmp/backup_rsync.log


#backup ROOT (ext3 partition of SD card)


tar cvjlf "$DEST"/SD_ROOT.tar.bz2 -C / --numeric-owner --exclude=dev/pts --exclude=proc --exclude=sys --exclude=media --exclude=mnt . 2>&1 | tee /tmp/backup_tar.log


echo Start: $BEGIN


echo End: `date`


[/code|


A backup created this way needs a complete original rootfs install as a base, so in case I need to restore, I need to recreate the ext3 file system, untar the original firmware rootfs tarball, and then untar the backup tarball in addition.


This has the one caveat of files deleted from the original install won't be deleted after the restore process, which makes the entire thing less elegant.


Well, maybe I will really use the boot-to-NAND method and tar the complete SD root fs instead. Might be the easiest and least dangerous option.


Daniel
 
Back
Top