I have a bunch of subvolumes on my server and about 5TB of data in them. Doing a full set of backups is time consuming to say the least! Luckily, BTRFS has an "incremental" backup feature. Basically it allows you to "send" a backup based on the difference between the current snapshot and the previous one. Confused? Here's a better explanation;
I have a subvolume called @movies for my Plex server. To make an initial backup using the btrfs send|receive you must make a read-only snapshot, then send|receive it to another btrfs file system. My @movies subvolume is in /mnt/pool and my backup drive is mounted at (oddly enough) /mnt/backup. I am keeping my backup snapshots in /mnt/pool/snapshots because snapshot must reside on the same filesystem as the source subvolume - but not necessarily in the same folder. Putting them in their own folder keeps things tidier.
Since all btrfs commands require root access, I use a root session to do these tasks (remember, I'm doing this for almost 2 dozen subvolumes!). Here how I made my initial snapshot and backup:
sudo -i
btrfs subvolume snapshot -r /mnt/pool/@movies /mnt/pool/snapshots/@movies_backup
I now have a read only (the -r option in the snapshot command) snapshot, so I can now "send" it to the backup file system.
btrfs send /mnt/pool/snapshots/@movies_backup | btrfs receive /mnt/backup
Note the "receive" command only wants the target folder. The received subvolume will have the same name as the sent one. Once this completes, I have a full copy of @movies in read-only format as @movies_backup. I did this last month. During the last few weeks I added 11 more movies to my collection and I wanted to back them up also. The full backup took several hours to complete because there are several hundred HD and 4K movies already in my collection. Luckily I can just back up the changes to the subvolume without doing a full copy.
To do this I need another read-only snapshot;
btrfs su sn -r /mnt/pool/@movies /mnt/pool/snapshots/@movies_backup1
Note that btrfs commands can be abbreviated to the least number of unique characters, so su = subvolume and sn=snapshot. Now I have two snapshots in my folder: movies_backup and movies_backup1. A quick file count shows @movie_backup contains 212 files and @movies_backup1 contains 223.
Here's the really cool part about btrfs and this snapshot thing: These two snapshots and the source subvolume are sharing data. That means although when I look at the contents of @movies_backup1 and compare it to @movies_backup, it appears that there are 212 copies of the same movies and 11 unique ones, the actuality is only one file exists of each of the duplicated files. I mean that the movie 'The Magnificent Seven (1960).mp4' is listed in both backups subvolumes and the original subvolume, it only actually exists once on the drive. All three subvolumes have their own metadata (file catalog info) but share file data. Anyway, back to the operation:
Now I can send only the difference between the two snapshots to the backup file system;
btrfs send -p /mnt/pool/snapshots/@movies_backup /mnt/pool/snapshots/@movies_backup1 | btrfs receive /mnt/backup
This sends only the difference (aka "partial" copy by using the -p option) between the two subvolumes to /mnt/backup as @moves_backup1. Because I added only 11 files, this completed in a few minutes rather than hours required for the first backup. Now /mnt/backup contains both subvolumes @movies_backup and @movies_backup1. Just as the source backups, @movies_backup contains 212 files and @movies_backup1 contains 223 - BUT THESE ALSO ARE SHARING THE DATA SPACE!
Now I can delete the first snapshot (@movies_backup) from both /mnt/pool/snapshots and /mnt/backup if I wish or leave them - because they are not actually using additional space!
I must keep at least one previous backup snapshot in /mnt/pool/snapshots so I have something to compare the next one too, and same for the receiving end - but since they take no extra space, I'm leaving them for now.
I have a subvolume called @movies for my Plex server. To make an initial backup using the btrfs send|receive you must make a read-only snapshot, then send|receive it to another btrfs file system. My @movies subvolume is in /mnt/pool and my backup drive is mounted at (oddly enough) /mnt/backup. I am keeping my backup snapshots in /mnt/pool/snapshots because snapshot must reside on the same filesystem as the source subvolume - but not necessarily in the same folder. Putting them in their own folder keeps things tidier.
Since all btrfs commands require root access, I use a root session to do these tasks (remember, I'm doing this for almost 2 dozen subvolumes!). Here how I made my initial snapshot and backup:
sudo -i
btrfs subvolume snapshot -r /mnt/pool/@movies /mnt/pool/snapshots/@movies_backup
I now have a read only (the -r option in the snapshot command) snapshot, so I can now "send" it to the backup file system.
btrfs send /mnt/pool/snapshots/@movies_backup | btrfs receive /mnt/backup
Note the "receive" command only wants the target folder. The received subvolume will have the same name as the sent one. Once this completes, I have a full copy of @movies in read-only format as @movies_backup. I did this last month. During the last few weeks I added 11 more movies to my collection and I wanted to back them up also. The full backup took several hours to complete because there are several hundred HD and 4K movies already in my collection. Luckily I can just back up the changes to the subvolume without doing a full copy.
To do this I need another read-only snapshot;
btrfs su sn -r /mnt/pool/@movies /mnt/pool/snapshots/@movies_backup1
Note that btrfs commands can be abbreviated to the least number of unique characters, so su = subvolume and sn=snapshot. Now I have two snapshots in my folder: movies_backup and movies_backup1. A quick file count shows @movie_backup contains 212 files and @movies_backup1 contains 223.
Here's the really cool part about btrfs and this snapshot thing: These two snapshots and the source subvolume are sharing data. That means although when I look at the contents of @movies_backup1 and compare it to @movies_backup, it appears that there are 212 copies of the same movies and 11 unique ones, the actuality is only one file exists of each of the duplicated files. I mean that the movie 'The Magnificent Seven (1960).mp4' is listed in both backups subvolumes and the original subvolume, it only actually exists once on the drive. All three subvolumes have their own metadata (file catalog info) but share file data. Anyway, back to the operation:
Now I can send only the difference between the two snapshots to the backup file system;
btrfs send -p /mnt/pool/snapshots/@movies_backup /mnt/pool/snapshots/@movies_backup1 | btrfs receive /mnt/backup
This sends only the difference (aka "partial" copy by using the -p option) between the two subvolumes to /mnt/backup as @moves_backup1. Because I added only 11 files, this completed in a few minutes rather than hours required for the first backup. Now /mnt/backup contains both subvolumes @movies_backup and @movies_backup1. Just as the source backups, @movies_backup contains 212 files and @movies_backup1 contains 223 - BUT THESE ALSO ARE SHARING THE DATA SPACE!
Now I can delete the first snapshot (@movies_backup) from both /mnt/pool/snapshots and /mnt/backup if I wish or leave them - because they are not actually using additional space!
I must keep at least one previous backup snapshot in /mnt/pool/snapshots so I have something to compare the next one too, and same for the receiving end - but since they take no extra space, I'm leaving them for now.
Comment