Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Snapshots and backups with btrfs to an external HD

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
scientific
Posts: 7
Joined: 2013-11-13 07:33

Snapshots and backups with btrfs to an external HD

#1 Post by scientific »

Hi there!

I made a script, to handle backups ans snapshots with btrfs to an external HD.
On short here:

You need one Subvolume for /. In this subvolume are all your other subvolumes (/home, /var/spool, ...). You only mount one subvolume for your whole system!
You need your subvolumes for manual snapshots (for example your mailserver-store in /var/spool, or your Videos ... whatever) and to exclude them from your entire system-snapshot. (You don't want .cache from your /home/user or /tmp, if it is not tmpfs!!)

The entry in /etc/fstab for your system is for a subvolume for /

Code: Select all

LABEL=SYSTEM            /                       btrfs   defaults,compress=lzo,space_cache,subvol=@debian-new            0       0
Then you have two mountpoints extra. One is for the entire btrfs-partition /dev/sdaX or LABEL=SYSTEM, the other one is for your external HD.

Code: Select all

LABEL=SYSTEM    /var/cache/btrfs_pool_SYSTEM    btrfs   defaults,noauto,comment=systemd.automount,noatime,compress=lzo,space_cache              0       0
/dev/sdbX                /var/cache/backup       btrfs   defaults,nofail,comment=systemd.automount,noauto,compress=lzo,space_cache       0       0
You can see, I'm using systemd and automount.

The commands:

Go to the directory, where the entire btrfs-partition is mounted

Code: Select all

cd /var/cache/btrfs_pool_SYSTEM
Create a simple snapshot on your local HD, where your system resides (LABEL=SYSTEM, or /dev/sdaX)

Code: Select all

mkbtrbackup create @debian-new
Create a snapshot on your local HD with interval-tag, and transfer it to the external Hd (/dev/sdbX)

Code: Select all

mkbtrbackup create @debian-new --interval hourly -x
If you want your first Snapshot to transfer also to the external HD

Code: Select all

mkbtrbackup transfer @debian-new.20141129-151331
If there is an older snapshot on your local AND the same on your external HD, only the differences between the older and the current snapshot is transferred. In the other case, the whole snapshot is transferred
Be careful, each subvolume in your snapshot is tested. If there is a new subvolume, this one is initially transferred. If you have modified the older snapshot (on the external or internal disk), datacorruption may be occur!!!

Delet a snapshot

You have 3 "stores" (I called them so for my script!!)
One is SNP. This is Your mountpoint for the btrfs-pool + a subdirectory there. Here are your snapshots stored.
The other is BKP. This is the mountpoint for your external HD + a subdirectoriy, where are the backups for your snapshots are stored.
The 3rd one is SRC. This is $PWD or the dirname of the given subvolume on the commandline.

So you can delete an entire snapshot from SNP or BKP or both together.
Delete a snapshot from your external HD

Code: Select all

mkbtrbackup delete BKP @debian-new.20141129-151331
Delete the same snapshot from your internal HD

Code: Select all

mkbtrbackup delete SNP @debian-new.20141129-151331
Delete a snapshot from your external AND your internal HD

Code: Select all

mkbtrbackup delete SNP BKP @debian-new.20141129-151331
To be safe for misstaken manipulations on snapshots, set them read-only (is done during create automagically)

Code: Select all

mkbtrbackup setprop ro @debian-new.20141129-151331
Just unlock a whole snapshot (i.e. to boot from it!)

Code: Select all

mkbtrbackup setprop rw @debian-new.20141129-151331
You will find a more detailed description (in german!!) on my page, where you can find the downloadlink also:
Check out http://linux.xundeenergie.at/doku.php?id=mkbtrbackup
Almost the same description is on debianforum.de https://wiki.debianforum.de/Snapshots_u ... _mit_btrfs

There is no warranity for your data, the script is bleeding edge and bugs are possible. Use it at your own risk!!!

Post Reply