How to rsync the / folder properly?

1

I have a btrfs snapshot of / and I want to rsync it with my current / folder. As form of "rollback" if you want. My question is what folder should I avoid for instance I should use -x option to prevent rsync on going down to other subvolumes but I should also exclude the tmp folder in order to prevent system crash anything else? what about /var, /run, /dev?

Dan

Posted 2015-01-16T18:59:54.483

Reputation: 69

What a coincidence, I wanted to ask something similar. I know some things (written below), but I´m not sure if this is enough (of course, else I wouldn´t want ask it). It worked already that way, but please keep in mind that I´m not sure how reliable this is. – deviantfan – 2015-01-23T12:07:03.213

Answers

1

I´m not sure if you want to do it with a live cd etc. or on the running system, so I´m answering for both.

Things to consider in both cases:

a) Use appropriate options for rsync to not only sync files, but also things like change date, access permission mask, Xattrs, Selinux informations, extended ACLs, hard links ... everything it can do. Reading the whole option list once to pick out everything necessary isn´t bad.

b) A Btrfs snapshot of one volume only includes this volume. If you have eg. a separate boot partition mounted on /boot, it isn´t covered by the backup, so it shouldn´t be synced => "-x" flag. Altough, with the process described below, you´ll get a view without mounted mount points anyways.

If done from a live CD:

a) Folders lime /tmp (if the content is on the real file system at all, instead of a run-time virtual one) won´t need additional consideration. Just overwrite them.

b) Virtual stuff like the majority of /dev entries (majority because /dev can contain some real files) won´t be there if viewed from the live CD => no problem. The few real files (if any) can be synced with rsync.

Nothing else comes to my mind for this case.

If done in the running system:

a) To prevent meddling with /dev and similar, you´ll need an "pure" view of your Btrfs file system, in addition to /, without additional mounted things. You can get it with mount --bind ... with some own folder. Take this as sync destination.

b) Just writing in a file opened by some other program would lead to problems, especially file constantly written to, like log files. Deleting the old file and creating a new one with own content allows the other program to access it´s old file until close. rsync does this by default, but pay attention to not pass options like --inplace !

c) As soon as rsync finished, reboot. The whole situation is tricky enough, so minimize the risk of some process mixing it´s old and new data and doing something strange while still running.

deviantfan

Posted 2015-01-16T18:59:54.483

Reputation: 207