Borg: Difference between revisions

From www.deloptes.org
Jump to navigation Jump to search
(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...")
 
No edit summary
 
Line 85: Line 85:
       -e 'pp:/backup/root/media' \
       -e 'pp:/backup/root/media' \
       /opt/backup/<machine>::{now:%Y-%m-%dT%H:%M:%S} \
       /opt/backup/<machine>::{now:%Y-%m-%dT%H:%M:%S} \
       /boot /backup/root
       /boot /boot/EFI /backup/root


=Unmount and remove snapshot===
=Unmount and remove snapshot===
Line 110: Line 110:


  lvconvert --merge /dev/<device>/<volume>-snap
  lvconvert --merge /dev/<device>/<volume>-snap
=Monitor borg process activity=
strace -fp $(ps -faxuww | grep borg | grep -v grep | awk '{print $2}') 2>&1| grep openat
=On errors=
[1] check and verify the backup to ensure the data is consistent
borg check --verify-data /opt/backup/<machine>
[2] remove cache if above does not help
ls ~/.cache/borg/
96d1fb3386b0a247a4ae6baa44095deac75a839a3fedaf77237663a1b72dc81b  CACHEDIR.TAG
mv ~/.cache/borg/ /tmp/
rm -rf ~/.cache/borg/

Latest revision as of 23:07, 6 August 2023

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 /boot/EFI /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

Monitor borg process activity

strace -fp $(ps -faxuww | grep borg | grep -v grep | awk '{print $2}') 2>&1| grep openat


On errors

[1] check and verify the backup to ensure the data is consistent

borg check --verify-data /opt/backup/<machine>

[2] remove cache if above does not help

ls ~/.cache/borg/
96d1fb3386b0a247a4ae6baa44095deac75a839a3fedaf77237663a1b72dc81b  CACHEDIR.TAG
mv ~/.cache/borg/ /tmp/
rm -rf ~/.cache/borg/