-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60d42e7
commit 3e0c9ed
Showing
10 changed files
with
264 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
let | ||
secretsDir = config.nix-bitcoin.secretsDir; | ||
in | ||
{ | ||
services.zfs.autoSnapshot.enable = true; | ||
|
||
# Only use daily, weekly, monthly ZFS snapshots | ||
systemd.timers = { | ||
zfs-snapshot-frequent.enable = false; | ||
zfs-snapshot-hourly.enable = false; | ||
# The daily snapshot is run by borgbackup-job-main.service | ||
zfs-snapshot-daily.enable = false; | ||
}; | ||
|
||
systemd.services.borgbackup-job-main = rec { | ||
requires = [ "zfs-snapshot-daily.service" ]; | ||
after = requires; | ||
}; | ||
|
||
programs.ssh.knownHosts."freak.seedhost.eu".publicKey = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBD2TmdE89ZD4XshcIcXZPLFC/nDxZdAr9yrH2/2OCNKEo/Ex60y8TQjp93isjdDj7Grf/GpW60OONfXTFe0r5iM="; | ||
|
||
services.borgbackup.jobs = { | ||
main = { | ||
startAt = "daily"; | ||
|
||
preHook = '' | ||
latest_daily_snap=$( | ||
shopt -s nullglob | ||
printf '%s\n' /.zfs/snapshot/*daily* | tail -1 | ||
) | ||
if [[ ! $latest_daily_snap ]]; then | ||
echo "Error: No daily snapshot found" | ||
exit 1 | ||
fi | ||
echo "Using $latest_daily_snap" | ||
cd $latest_daily_snap | ||
''; | ||
|
||
paths = [ "var/lib" ]; | ||
|
||
exclude = [ | ||
"var/lib/bitcoind/blocks" | ||
"var/lib/bitcoind/chainstate" | ||
"var/lib/bitcoind/indexes" | ||
"var/lib/liquidd/*/blocks" | ||
"var/lib/liquidd/*/chainstate" | ||
"var/lib/liquidd/*/indexes" | ||
"var/lib/electrs" | ||
"var/lib/fulcrum" | ||
"var/lib/nbxplorer" | ||
"var/lib/duplicity" | ||
"var/lib/onion-addresses" | ||
|
||
"var/lib/i2pd" | ||
"var/lib/redis" | ||
"var/lib/udisks2" | ||
"var/lib/usbguard" | ||
|
||
"var/lib/acme" | ||
"var/lib/dovecot" | ||
"var/lib/dhparams" # from dovecot | ||
"var/lib/postfix" | ||
"var/lib/rspamd" | ||
|
||
"var/lib/machines" | ||
"var/lib/private" | ||
"var/lib/systemd" | ||
]; | ||
|
||
repo = "nixbitcoin@freak.seedhost.eu:borg-backup"; | ||
doInit = false; | ||
encryption = { | ||
mode = "repokey"; | ||
passCommand = "cat ${secretsDir}/backup-encryption-password"; | ||
}; | ||
environment = { | ||
BORG_RSH = "ssh -i ${secretsDir}/ssh-key-seedhost"; | ||
# TODO-EXTERNAL: Use this definition when the borg job wrapper script | ||
# has been fixed in the borgbackup.nix NixOS module | ||
# BORG_REMOTE_PATH = "$HOME/.local/bin/borg"; | ||
BORG_REMOTE_PATH = "/home34/nixbitcoin/.local/bin/borg"; | ||
}; | ||
compression = "zstd"; | ||
extraCreateArgs = "--stats"; # Print stats after backup | ||
prune.keep = { | ||
within = "1d"; # Keep all archives from the last day | ||
daily = 4; | ||
weekly = 2; | ||
monthly = 2; | ||
}; | ||
# Compact (free repo storage space) every 7 days | ||
postPrune = '' | ||
if (( (($(date +%s) / 86400) % 7) == 0 )); then | ||
borg compact | ||
fi | ||
''; | ||
}; | ||
}; | ||
|
||
nix-bitcoin.secrets = { | ||
backup-encryption-password.user = "root"; | ||
ssh-key-seedhost = { | ||
user = "root"; | ||
permissions = "400"; | ||
}; | ||
}; | ||
nix-bitcoin.generateSecretsCmds.backups = '' | ||
makePasswordSecret backup-encryption-password | ||
# Generate a dummy file so that setup-secrets doesn't fail | ||
touch ssh-key-seedhost | ||
''; | ||
|
||
# Use borg 1.2.1 (the latest 1.2.* release) | ||
# TODO-EXTERNAL: Remove this when 1.2.1 has landed in nixpkgs stable | ||
nixpkgs.overlays = [ | ||
(_: _: { inherit (config.nix-bitcoin.pkgs.pkgsUnstable) borgbackup; }) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## | ||
## Warning: This is a very rough sketch | ||
## | ||
|
||
#――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― | ||
# 1. Deploy borg binary on seedhost | ||
|
||
TMPDIR=$(mktemp -d) | ||
export GNUPGHOME=$TMPDIR | ||
|
||
# fetch dev key (tw@waldmann-edv.de) | ||
gpg --recv-keys --keyserver hkps://keyserver.ubuntu.com 9F88FB52FAF7B393 | ||
|
||
# Download `linuxold` release which is compatible with the glibc version on seedhost | ||
curl -L https://github.com/borgbackup/borg/releases/download/1.2.1/borg-linuxold64 -O | ||
curl -L https://github.com/borgbackup/borg/releases/download/1.2.1/borg-linuxold64.asc -O | ||
gpg --verify borg-linuxold64.asc | ||
|
||
rm -rf $TMPDIR | ||
|
||
#――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― | ||
# 2. Init borg backup repo on seedhost | ||
|
||
# Run the following commands in a nix shell | ||
nix shell nixpkgs/29399e5ad1660668b61247c99894fc2fb97b4e74#borgbackup | ||
|
||
# Ensure borg version is >= 1.2.1 | ||
borg --version | ||
|
||
if [[ ! $XDG_RUNTIME_DIR ]]; then | ||
echo 'Error: Missing env var XDG_RUNTIME_DIR' | ||
return 1 | ||
fi | ||
export secrets=$XDG_RUNTIME_DIR/borg-secrets | ||
mkdir -p $secrets | ||
install -m 600 <(gpg --decrypt ../secrets/nixbitcoin.org/ssh-key-seedhost.gpg) $secrets/ssh-key-seedhost | ||
install -m 600 <(gpg --decrypt ../secrets/nixbitcoin.org/backup-encryption-password.gpg) $secrets/backup-encryption-password | ||
|
||
export BORG_REPO=nixbitcoin@freak.seedhost.eu:borg-backup | ||
export BORG_RSH="ssh -i $secrets/ssh-key-seedhost" | ||
export BORG_REMOTE_PATH='$HOME/.local/bin/borg' | ||
export BORG_PASSCOMMAND="cat $secrets/backup-encryption-password" | ||
borg init --encryption=repokey --storage-quota=400G | ||
|
||
debugCmds() { | ||
borg info | ||
|
||
ssh freak.seedhost.eu 'ls -alt' | ||
ssh freak.seedhost.eu 'ls -al borg-backup' | ||
ssh freak.seedhost.eu 'ls -al borg-backup/data' | ||
# Delete repo | ||
ssh freak.seedhost.eu 'rm -rf borg-backup' | ||
|
||
# This can be run on nixbitoin.org to manage the backup | ||
borg-job-main ... | ||
borg-job-main list | ||
} | ||
|
||
rm -rf $secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.