# Setting up backup disk

# Prepare partition

  1. Attach disk to laptop
  2. Start gparted (sudo gparted), delete existing partitions and create a single new one; partition table should be gpt
  3. Encrypt the partition with LUKS: sudo cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 -y /dev/DEVICENAME
  4. Open the encrypted partition: sudo cryptsetup luksOpen /dev/DEVICENAME backup10tb
  5. Format the encrypted partition with btrfs: sudo mkfs.btrfs -L "backup10tb" /dev/mapper/backup10tb
  6. Mount the partition: sudo mkdir /mnt/backup10tb && sudo mount /dev/mapper/backup10tb /mnt/backup10tb

# Create initial subvolumes on external disk

  1. cd /mnt/backup10tb
  2. sudo btrfs subvolume create ./annex
  3. sudo btrfs subvolume create ./backup

# Send backups to external disk

  1. Create new snapshots for all partitions: for i in @ @etckeeper @home @repos @root; do btrfs subvolume snapshot -r /mnt/master/$i /mnt/master/backups/for-external/$i/$(date "+%Y-%m-%d")--01 ; done
  2. Create the target diretory: for i in @ @etckeeper @home @repos @root; do mkdir /mnt/backup10tb/backup/$i/; done
  3. Send snapshots to backup disk: for i in @ @etckeeper @home @repos @root ; do btrfs send /mnt/master/backups/for-external/$i/2019-11-24--01 | btrfs receive /mnt/backup10tb/backup/$i/ ; done

# Clone annex repos

  1. cd /mnt/backup10tb/annex
  2. git clone /home/mfk/repos/annex/newspaper/ -o remote-name
  3. cd newspaper
  4. git config user.name "Name"
  5. git config user.email info@example.org
  6. git annex init "Repo Name"
  7. git annex get --from remote-name --all
  8. git annex sync

# Send incremental backups

# btrfs subvolumes

  1. Create new snapshots for all partitions: for i in @ @etckeeper @home @repos @root; do btrfs subvolume snapshot -r /mnt/master/$i /mnt/master/backups/for-external/$i/$(date "+%Y-%m-%d")--02 ; done
  2. Send incremental snapshots to backup disk: for i in @ @etckeeper @home @repos @root ; do btrfs send -p /mnt/master/backups/for-external/$i/2019-11-24--01 /mnt/master/backups/for-external/$i/2019-11-24--02 | btrfs receive /mnt/backup10tb/backup/$i/ ; done

# Annex repos

  1. cd /mnt/backup10tb/annex/newspaper/
  2. git annex sync
  3. git annex get --from remote-name --all
  4. git annex sync