Usability tips: Backup and snapshots

Date: 2021/11/02 (initial publish), 2022/08/22 (last update)

Previous Post Top Next Post

TOC

Backup and snapshot

For backup, data needs to be moved to physically separate device. rsync ... is my choice to do this.

For snapshot, data can stay on the same device . btrfs subvolume snapshot ... is my choice to do this.

I created bss script to help me do these easily and its examples contain key parts of the settings. Here are the basic tricks used in them..

Secure backup

In order to securely backup private data using non-secure remote storage, data needs to be encrypted. Roughly, the following is an approach:

This can be done using following tricks.

Create and format an encrypted filesystem in a disk image

$ dd bs=1 count=0 if=/dev/zero of=disk.img seek=7000M
$ mkdir disk
$ cryptsetup luksFormat disk.img
WARNING: ...
 ...
$ sudo cryptsetup open disk.img disk --type luks
Enter passphrase for disk.img: *****
$ ls -l /dev/mapper
total 0
crw------- 1 root root 10, 236 Nov  3 07:45 control
lrwxrwxrwx 1 root root       7 Nov  3 12:04 disk -> ../dm-0
$ sudo mkfs.btrfs /dev/mapper/disk
 ...
   ID        SIZE  PATH
    1     6.82GiB  /dev/mapper/disk

$ sudo mount /dev/mapper/disk /mnt
$ sudo chown 1000:1000 /mnt
$ sudo umount /mnt
$ cryptsetup close disk

Mount and use an encrypted filesystem in a disk image

$ mkdir -p ~/path/to/mnt
$ sudo cryptsetup open disk.img disk --type luks
Enter passphrase for disk.img: *****
$ sudo mount /dev/mapper/disk ~/path/to/mnt
... (use files in ~/path/to/mnt as a user)
$ sudo umount /dev/mapper/disk
$ sudo cryptsetup close disk

In order to skip passphrase hassle, let’s use Gnome keyring.

Let me store my_pass_phrase_value in Gnome keyring.

$ secret-tool store --Label='LUKS passowrd for disk.img' LUKS disk_img

Then, use Gnome keyring to decrypt luks device.

$ secret-tool lookup LUKS disk_img | \
  cryptsetup open disk.img disk --type luks --key-file -

This avoids storing key file data in plain text.

For ~/path/to/mnt, use~/Document. For ~/.gnupg, ~/.ssh, bind mount may be an idea.

Hints for LUKS and its auto-unlocking on the web

Previous Post Top Next Post