Borg

From www.deloptes.org
Revision as of 23:56, 6 August 2023 by Admin (talk | contribs) (Created page with " =Introduction= Brief documentation on [https://www.borgbackup.org/| borg] backup system =Setup= Assume following ;<machine> : is the machine to backup ;<host> : is the b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

Brief documentation on borg backup system

Setup

Assume following

<machine>
is the machine to backup
<host>
is the backup host
/opt/backup
is the backup location on the backup host <host>
<user>
is the ssh user with permission to write into /opt/backup
<device>
is the volume group
<volume>
is the logical volume

Configure LVM

Based on this howto edit

/etc/lvm/lvm.conf

Search for the word autoextend. By default, the value will be similar to below. Change the 100 to 75 here, if so auto extend threshold is 75 and the auto-extend percent is 20, it will expand the size by 20 Percent

If the snapshot volume reaches 75% it will automatically expand the size of the snap volume by 20% more. Thus, we can expand automatically. Save and exit.

This will save snapshots from overflow drop. This will also help you to save more time. LVM is the only Partition method in which we can expand more and have many features such as thin Provisioning, Striping, Virtual volume, and more Using thin-pool, let us see them in the next topic.

Initialize backup

borg init --encryption=repokey <user>@<host>:/opt/backup/<machine>

or for local backup

borg init --encryption=repokey /opt/backup/<machine>

Export the key

borg key export /opt/backup/<machine> /root/borgbackup-key-<machine>.export

Create LVM snapshot

lvcreate -L 1GB -s -n <volume>-snap /dev/<device>/<volume>

Mount LVM snapshot

mkdir -p /backup/<volume> 
mount /dev/<device>/<volume>-snap /backup/<volume> 

Moiunting XFS volumes

XFS volumes use UUID and it can not be mounted twice with the same UUID

Based on this howto there are 2 things that you can do:

[1] Mount the filesystem without using its UUID

mount -o nouuid /dev/<device>/<volume>-snap /backup/<volume> 

or:

[2] Change the UUID of the snapshot LVM

xfs_repair -L /dev/<device>/<volume>-snap 
xfs_admin -U $(uuidgen) /dev/<device>/<volume>-snap 
mount /dev/<device>/<volume>-snap /backup/<volume> 

Create backup

borg create --progress --stats --compression zstd,10 \
     -e 'pp:/backup/root/sys' \
     -e 'pp:/backup/root/proc' \
     -e 'pp:/backup/root/dev' \
     -e 'pp:/backup/root/run' \
     -e 'pp:/backup/root/tmp' \
     -e 'pp:/backup/root/var/tmp' \
     -e 'pp:/backup/root/var/log' \
     -e 'pp:/backup/root/home' \
     -e 'pp:/backup/root/media' \
     /opt/backup/<machine>::{now:%Y-%m-%dT%H:%M:%S} \
     /boot /backup/root

Unmount and remove snapshot==

umount /dev/<device>/<volume>-snap && \
lvremove -y /dev/<device>/<volume>-snap


List archives

borg list /opt/backup/<machine>

List backup

borg list /opt/backup/<machine>::<backup>

Restoring Snapshot or Merging

Unmount first

umount /dev/<device>/<volume>-snap

Merge

lvconvert --merge /dev/<device>/<volume>-snap