Skip to content

Commit a4565b6

Browse files
committed
Add prefix-ed borg prune command
Also adjust archive naming to make for easy prefix-ing
1 parent b637bf7 commit a4565b6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This repo will soon contain a docker image and kubernetes resource YAMLs for bac
1616
- Uses this dictionary to save backups using the PVC name rather than the volume name
1717
- The PVC name is typically specified by the user in a PVC resource YAML
1818
- The volume name may be automatically generated by a dynamic volume provisioner
19-
- Goal is to have archives in borg repo named something like `2020-03-01-sonarr` rather than `2020-03-01-pvc-b1397318-8fa4-4216-aa6b-6568d1394e89`
19+
- Goal is to have archives in borg repo named something like `sonarr-2020-03-01` rather than `pvc-b1397318-8fa4-4216-aa6b-6568d1394e89-2020-03-01`
2020
- Archive contents will be a 1:1 reproduction of the PVC storage contents at time of archive creation
2121
- TBD:
2222
- Generic script to restore a borg backup to a k8s volume

k8s-volume-backup.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@
3737
# get the pvc metadata name using the parsed get pvc output
3838
pvc_name = pvc_data.get(volume_name, "")
3939
if pvc_name:
40-
# create a borg archive named according to YYYY-MM-DD-pvc.metadata.name, cd-ing into the volume directory first
40+
# create a borg archive named according to pvc.metadata.name-YYYY-MM-DD, cd-ing into the volume directory first
4141
# contents of archive will be identical to contents of the PVC at time of archive creation, to simplify backup restore
42-
# to restore a backup to the current folder: 'borg extract ${REPOSITORY}::YYYY-MM-DD-pvc.metadata.name'
43-
# example backup command : borg create /mnt/repo::2020-02-01-sonarr .
44-
# example restory command: borg extract /mnt/repo::2020-02-01-sonarr
42+
# to restore a backup to the current folder: 'borg extract ${REPOSITORY}::pvc.metadata.name-YYYY-MM-DD'
43+
# example backup command : borg create /mnt/repo::sonarr-2020-02-01 .
44+
# example restory command: borg extract /mnt/repo::sonarr-2020-02-01
4545
subprocess.check_call(["borg", "create", "-v", "--stats", "--compression", "auto,zstd",
46-
f"{REPOSITORY}::{{now:%Y-%m-%d}}-{pvc_name}", "."],
46+
f"{REPOSITORY}::{pvc_name}-{{now:%Y-%m-%d}}", "."],
4747
cwd=volume, env={"BORG_PASSPHRASE": BORG_PASSPHRASE})
48+
49+
# prune borg repo, removing old backups for this pvc_name
50+
# note the --prefix, to limit pruning
51+
subprocess.check_call(["borg", "prune", "-v", "--list", REPOSITORY, "--prefix", pvc_name,
52+
"--keep-daily=7", "--keep-weekly=4", "--keep-monthly=6", "--keep-yearly=1"],
53+
env={"BORG_PASSPHRASE": BORG_PASSPHRASE})

0 commit comments

Comments
 (0)