How to make a tar backup of a root filesystem? [closed]
Asked Answered
M

1

7

I have linux installed on SD card, I used this command to install the rootfs

tar xpjf rootfs.tar.bz -C /mnt/rootfs/

Now, I made some changes to the rootfs and I would like to create a backup that I can use with the same command above, I tried using:

tar cpjf rootfs.tar.bz2 /mnt/rootfs
and
tar cpjf rootfs.tar.bz2 -C / mnt/rootfs
I also tried
tar cpjf rootfs.tar.bz2 /mnt/rootfs/*

And tried:

cd /mnt/rootfs
tar -cvpjf rootfs.tar.bz2 --exclude=/rootfs.tar.bz2 .
tar: ./rootfs.tar.bz2: file changed as we read it

but I end up with an archive that has two levels before the file system i.e mnt/rootfs/files What am I doing wrong ?

Mudcat answered 9/7, 2012 at 12:35 Comment(1)
well answered here : help.ubuntu.com/community/BackupYourSystem/TARCasar
N
14

That's because it starts from current working directory, you can do:

cd /mnt/rootfs
tar cpjf /rootfs.tar.bz2 .

And that should create an archive at /rootfs.tar.bz2 with its root at the contents of /mnt/rootfs/

Naara answered 9/7, 2012 at 12:40 Comment(10)
Don't use *. That might fail with files named like "--filename". Instead, use ./* .Sungsungari
Also, it might be worth noting that ./* (and *) might not pick up files whose names begin with a dot.Sungsungari
Thanks for the tip, i used * as the user posted the question with that, corrected the answer ;)Naara
@AmbrozBizjak so how do I include hidden files ?Mudcat
@mux tar cjpf /rootfs.tar.bz2 .Sungsungari
@mux the alternative is stuff like ./* ./.* which you may notice doesn't work quire right, because ./.* will include . and ... Another problem with wildcards (./*) is that if there's nothing in the folder at all, it will not expand, and tar will try to pack a file named ./*, which does not exist.Sungsungari
Thank you all, I just tried installing from the backup and it boots fine.Mudcat
@Naara you really should change that to a dot, its the only solution that just works right in all casesSungsungari
@AmbrozBizjak I will make another backup just in case, but, just to be clear, the right way to include everything (including hidden files) is tar cjpf /rootfs.tar.bz2 . right ?Mudcat
tar cpjf /rootfs.tar.bz2 -C /mnt/rootfs . Where -C means "cd into <path> then ...." Is simpler.Leund

© 2022 - 2024 — McMap. All rights reserved.