Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement ZFS-backed rsnapshot backup #1325

Draft
wants to merge 58 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2466a3f
feat: zfs-based rsnapshot backup
singingtelegram Oct 19, 2022
db127fe
more work
singingtelegram Oct 19, 2022
d8bdaec
lint & shellcheck
singingtelegram Oct 19, 2022
be1b32c
Update rsnapshot-zfs.conf
singingtelegram Oct 24, 2022
3fe9d12
Revert "Update rsnapshot-zfs.conf"
singingtelegram Oct 24, 2022
849913a
Merge remote-tracking branch 'origin/master' into zfs-backup
singingtelegram Oct 25, 2022
556f887
remove old backup jobs
singingtelegram Oct 25, 2022
35f8d53
fix: syntax
singingtelegram Oct 25, 2022
cf4adcd
change time
singingtelegram Oct 26, 2022
dc4f458
Merge remote-tracking branch 'origin/master' into zfs-backup
singingtelegram Oct 29, 2022
4a4fd79
feat: use zfs native compression for sql
singingtelegram Oct 29, 2022
6021225
fix: zfs send args
singingtelegram Nov 6, 2022
823d271
feat: syncoid instead of raw zfs send commands
singingtelegram Nov 6, 2022
44e5124
feat: logging and logrotate
singingtelegram Nov 7, 2022
515e96f
feat: reduce verbosity
singingtelegram Nov 21, 2022
c8f4f51
fix: disable healthcheck on videolan-ftp
singingtelegram Oct 30, 2022
d37300d
Update vcsrepo to 5.3.0 (#1340)
Kalissaac Oct 30, 2022
a5066c9
Add `*.new.o.b.e` to HAProxy (#1339)
Kalissaac Oct 30, 2022
771e484
update fw
singingtelegram Nov 2, 2022
b4d9ad6
foo
singingtelegram Nov 2, 2022
11b3ac9
fw update pt3
singingtelegram Nov 2, 2022
4c1b8f0
elts updates: use ocf mirrors and use backport kernel
singingtelegram Nov 2, 2022
0e54a74
Ignore DNS resolution timeout error (#1341)
Kalissaac Nov 3, 2022
62aecdb
fix: chattr exec
singingtelegram Nov 8, 2022
9987254
fix: syntax
singingtelegram Nov 8, 2022
8ae3563
Revert social shorturl to regular form (#1342)
Kalissaac Nov 9, 2022
f004497
cleanup
singingtelegram Nov 15, 2022
9f47a4c
Add vaultwarden.o.b.e to load balancer (#1344)
Kalissaac Dec 9, 2022
a691cdf
doc: add comments to octocatalog-diff script
ethanwu10 Jan 17, 2023
af1f2db
fix(mirrors): reload nginx when certs change (#1345)
ethanwu10 Jan 17, 2023
aa74f2c
chore: add corruption-new
singingtelegram Jan 19, 2023
17459ce
fix: add new hpc to firewall
singingtelegram Jan 19, 2023
a66dee0
fix: wrong gateway
singingtelegram Jan 19, 2023
46e09bd
ncograin root (#1346)
singingtelegram Jan 19, 2023
8140ffa
changed apply to spring 2023 (#1348)
dpark00 Jan 25, 2023
8bf7f2c
add ewdc ip
singingtelegram Jan 25, 2023
1321235
fix: update chrome and electron apps automatically (#1349)
singingtelegram Jan 30, 2023
bf3c305
fix: guess what they changed the codename in 11!!
singingtelegram Jan 30, 2023
310c0d1
automatically bump version to 1.5.0 (#1343)
ocfbot Feb 2, 2023
dfd6e6d
remove rmxu from root staff (#1350)
axmmisaka Feb 3, 2023
7994dcf
sp23: trim root ACL
nikhiljha Feb 3, 2023
62eec41
fix: proper root principal for ncograin
singingtelegram Feb 15, 2023
62ffaf2
Add SSL configuration to windshear (#1354)
Kalissaac Feb 23, 2023
9221801
fix: don't redirect on ocf.b.e (#1251)
singingtelegram Feb 28, 2023
41196fc
Add slidingsync.matrix (#1355)
Kalissaac Feb 28, 2023
72a3630
Update www.pp
singingtelegram Feb 28, 2023
e108471
Add subdomains@ RT queue (#1356)
Kalissaac Mar 2, 2023
4086720
Add subdomains shorturl (#1357)
Kalissaac Mar 2, 2023
e871503
Update opstaff hiring form link (#1358)
Kalissaac Apr 5, 2023
7d483ee
Add matrix client well-known authentication issuer (#1359)
Kalissaac Apr 11, 2023
9d6bfed
fix: TLSv1.2
singingtelegram Apr 11, 2023
ed3adc8
revert
singingtelegram Apr 11, 2023
c55c47e
Update GitHub SSH public key (#1360)
Kalissaac Apr 11, 2023
6e8d3f3
Fix matrix well-known typo
Kalissaac Apr 12, 2023
f360be9
feat: smart monitoring (#1362)
singingtelegram Apr 17, 2023
a2035a1
fix: do not send intermediate snapshots
Apr 30, 2023
d66a8d1
Revert "fix: do not send intermediate snapshots"
singingtelegram Aug 4, 2023
1037876
fix merge conflict
singingtelegram Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hieradata/dummy_secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ocfbackups::box:
api_client_id: dummy_client_id
api_client_secret: dummy_client_secret
ocfbackups::mysql::password: dummypassword
ocfbackups::offsite_host: dummyhost

sensu::redis::password: dummypassword

Expand Down
2 changes: 1 addition & 1 deletion modules/ocf_backups/files/backup-mysql
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ parallel -i \
--triggers \
--routines \
--single-transaction \
--databases {} | pigz > "mysql-{}-$(date +%F).sql.gz"' -- $databases
--databases {} > "mysql-{}-$(date +%F).sql"' -- $databases
2 changes: 1 addition & 1 deletion modules/ocf_backups/files/backup-pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -euo pipefail

# Dumps the entire PostgreSQL instance to one .sql file.
# Requires that a valid ~/.pgpass file be available on the PostgreSQL host
ssh -K ocfbackups@postgres 'pg_dumpall -U postgres -h localhost | pigz' > "pgsql-all-$(date +%F).sql.gz"
ssh -K ocfbackups@postgres 'pg_dumpall -U postgres -h localhost' > "pgsql-all-$(date +%F).sql"
5 changes: 5 additions & 0 deletions modules/ocf_backups/files/backup-zfs-logrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/var/log/ocf-backup-zfs.log {
rotate 100
daily
compress
}
19 changes: 19 additions & 0 deletions modules/ocf_backups/files/backup-zfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

CURRENT_SNAPSHOT_FILE=/opt/share/backups/current-zfs-snapshot
CURRENT_SNAPSHOT=$(cat $CURRENT_SNAPSHOT_FILE)
OFFSITE_HOST=$(cat /opt/share/backups/offsite-host)
echo "$CURRENT_SNAPSHOT"

rsnapshot -c /opt/share/backups/rsnapshot-zfs.conf sync
rsnapshot -c /opt/share/backups/rsnapshot-zfs-mysql.conf sync
rsnapshot -c /opt/share/backups/rsnapshot-zfs-git.conf sync
rsnapshot -c /opt/share/backups/rsnapshot-zfs-pgsql.conf sync

zfs-auto-snapshot --syslog --label=after-backup --keep=10 // | awk -F"," '{print $1}' | cut -c2- > $CURRENT_SNAPSHOT_FILE
NEW_SNAPSHOT=$(cat $CURRENT_SNAPSHOT_FILE)

echo "$CURRENT_SNAPSHOT"
echo "$NEW_SNAPSHOT"

syncoid -r --no-sync-snap --sendoptions "L w c" backup/encrypted/rsnapshot "$OFFSITE_HOST":data1/ocfbackup/encrypted/rsnapshot
45 changes: 45 additions & 0 deletions modules/ocf_backups/files/rsnapshot-zfs-git.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#################################################
# rsnapshot.conf - rsnapshot configuration file #
#################################################
# #
# PLEASE BE AWARE OF THE FOLLOWING RULES: #
# #
# This file requires tabs between elements #
# #
# Directories require a trailing slash: #
# right: /home/ #
# wrong: /home #
# #
#################################################

config_version 1.2

cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/local/bin/rsync-no-vanished
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger

# remote backups require login as ocfbackups, then `sudo rsync-no-vanished'
cmd_preexec /usr/bin/kinit -t /opt/share/backups/ocfbackups.keytab ocfbackups
cmd_postexec /usr/bin/kdestroy

# default is "--delete --numeric-ids --relative --delete-excluded"
# we add the 'sudo rsync-no-vanished' bits
rsync_long_args --delete --numeric-ids --relative --delete-excluded --rsync-path="sudo ionice -c2 -n7 nice -n15 /usr/local/bin/rsync-no-vanished"

no_create_root 1
one_fs 1
sync_first 1

lockfile /run/rsnapshot.pid

# backup root directory
snapshot_root /backup/encrypted/rsnapshot/git/

retain daily 1
# backup points/scripts
# nfs (homedirs, webdirs)

# scripts
backup_script /opt/share/backups/backup-git .
45 changes: 45 additions & 0 deletions modules/ocf_backups/files/rsnapshot-zfs-mysql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#################################################
# rsnapshot.conf - rsnapshot configuration file #
#################################################
# #
# PLEASE BE AWARE OF THE FOLLOWING RULES: #
# #
# This file requires tabs between elements #
# #
# Directories require a trailing slash: #
# right: /home/ #
# wrong: /home #
# #
#################################################

config_version 1.2

cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/local/bin/rsync-no-vanished
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger

# remote backups require login as ocfbackups, then `sudo rsync-no-vanished'
cmd_preexec /usr/bin/kinit -t /opt/share/backups/ocfbackups.keytab ocfbackups
cmd_postexec /usr/bin/kdestroy

# default is "--delete --numeric-ids --relative --delete-excluded"
# we add the 'sudo rsync-no-vanished' bits
rsync_long_args --delete --numeric-ids --relative --delete-excluded --rsync-path="sudo ionice -c2 -n7 nice -n15 /usr/local/bin/rsync-no-vanished"

no_create_root 1
one_fs 1
sync_first 1

lockfile /run/rsnapshot.pid

# backup root directory
snapshot_root /backup/encrypted/rsnapshot/mysql/

retain daily 1
# backup points/scripts
# nfs (homedirs, webdirs)

# scripts
backup_script /opt/share/backups/backup-mysql .
45 changes: 45 additions & 0 deletions modules/ocf_backups/files/rsnapshot-zfs-pgsql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#################################################
# rsnapshot.conf - rsnapshot configuration file #
#################################################
# #
# PLEASE BE AWARE OF THE FOLLOWING RULES: #
# #
# This file requires tabs between elements #
# #
# Directories require a trailing slash: #
# right: /home/ #
# wrong: /home #
# #
#################################################

config_version 1.2

cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/local/bin/rsync-no-vanished
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger

# remote backups require login as ocfbackups, then `sudo rsync-no-vanished'
cmd_preexec /usr/bin/kinit -t /opt/share/backups/ocfbackups.keytab ocfbackups
cmd_postexec /usr/bin/kdestroy

# default is "--delete --numeric-ids --relative --delete-excluded"
# we add the 'sudo rsync-no-vanished' bits
rsync_long_args --delete --numeric-ids --relative --delete-excluded --rsync-path="sudo ionice -c2 -n7 nice -n15 /usr/local/bin/rsync-no-vanished"

no_create_root 1
one_fs 1
sync_first 1

lockfile /run/rsnapshot.pid

# backup root directory
snapshot_root /backup/encrypted/rsnapshot/pgsql/

retain daily 1
# backup points/scripts
# nfs (homedirs, webdirs)

# scripts
backup_script /opt/share/backups/backup-pgsql .
74 changes: 74 additions & 0 deletions modules/ocf_backups/files/rsnapshot-zfs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#################################################
# rsnapshot.conf - rsnapshot configuration file #
#################################################
# #
# PLEASE BE AWARE OF THE FOLLOWING RULES: #
# #
# This file requires tabs between elements #
# #
# Directories require a trailing slash: #
# right: /home/ #
# wrong: /home #
# #
#################################################

config_version 1.2

cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/local/bin/rsync-no-vanished
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger

# remote backups require login as ocfbackups, then `sudo rsync-no-vanished'
cmd_preexec /usr/bin/kinit -t /opt/share/backups/ocfbackups.keytab ocfbackups
cmd_postexec /usr/bin/kdestroy

# default is "--delete --numeric-ids --relative --delete-excluded"
# we add the 'sudo rsync-no-vanished' bits
rsync_long_args --delete --numeric-ids --relative --delete-excluded --rsync-path="sudo ionice -c2 -n7 nice -n15 /usr/local/bin/rsync-no-vanished"

no_create_root 1
one_fs 1
sync_first 1

lockfile /run/rsnapshot.pid

# backup root directory
snapshot_root /backup/encrypted/rsnapshot/

retain daily 1
# backup points/scripts
# scripts
# nfs (homedirs, webdirs)
backup ocfbackups@filehost:/opt/homes/ nfs/

# remote servers
backup ocfbackups@hal:/etc/libvirt/qemu/ servers/vm_xml/hal/
backup ocfbackups@jaws:/etc/libvirt/qemu/ servers/vm_xml/jaws/
backup ocfbackups@pandemic:/etc/libvirt/qemu/ servers/vm_xml/pandemic/
backup ocfbackups@riptide:/etc/libvirt/qemu/ servers/vm_xml/riptide/
backup ocfbackups@scurvy:/etc/libvirt/qemu/ servers/vm_xml/scurvy/
backup ocfbackups@kerberos:/var/lib/heimdal-kdc/ servers/kerberos/
backup ocfbackups@kerberos:/var/backups/kerberos/ servers/kerberos/
backup ocfbackups@ldap:/var/lib/ldap/ servers/ldap/
backup ocfbackups@ldap:/var/backups/ldap/ servers/ldap/

backup ocfbackups@puppet:/etc/puppetlabs/ servers/puppet/
backup ocfbackups@puppet:/opt/puppetlabs/ servers/puppet/

backup ocfbackups@puppetdb:/etc/puppetlabs/puppet/ssl/ servers/puppetdb/

backup ocfbackups@munin:/var/lib/munin/ servers/munin/

backup ocfbackups@apt:/opt/apt/ servers/apt/

backup ocfbackups@jenkins:/var/lib/jenkins/ servers/jenkins/

backup ocfbackups@rancid:/var/lib/rancid/ servers/rancid/

backup ocfbackups@ns:/etc/bind/keys/ servers/ns/

backup ocfbackups@irc:/var/lib/znc/ servers/irc/

# vim: ts=16 sts=16 sw=16 noet
9 changes: 9 additions & 0 deletions modules/ocf_backups/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
ensure => directory,
group => ocfroot,
mode => '0750';

'/opt/share/backups/offsite-host':
content => lookup('ocfbackups::offsite_host'),
owner => root,
group => root,
mode => '0400';

'/etc/logrotate.d/backup-zfs':
source => 'puppet:///modules/ocf_backups/backup-zfs-logrotate';
}

# keytab for ocfbackups user, used to rsync from remote servers
Expand Down
56 changes: 20 additions & 36 deletions modules/ocf_backups/manifests/rsnapshot.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
'/opt/share/backups/rsnapshot.conf':
source => 'puppet:///modules/ocf_backups/rsnapshot.conf';

'/opt/share/backups/rsnapshot-zfs.conf':
source => 'puppet:///modules/ocf_backups/rsnapshot-zfs.conf';

'/opt/share/backups/rsnapshot-zfs-mysql.conf':
source => 'puppet:///modules/ocf_backups/rsnapshot-zfs-mysql.conf';
'/opt/share/backups/rsnapshot-zfs-pgsql.conf':
source => 'puppet:///modules/ocf_backups/rsnapshot-zfs-pgsql.conf';
'/opt/share/backups/rsnapshot-zfs-git.conf':
source => 'puppet:///modules/ocf_backups/rsnapshot-zfs-git.conf';

'/usr/local/sbin/backup-zfs.sh':
source => 'puppet:///modules/ocf_backups/backup-zfs.sh',
mode => '0755';

# TODO: update for ZFS
'/opt/share/backups/check-rsnapshot-backups':
source => 'puppet:///modules/ocf_backups/check-rsnapshot-backups',
mode => '0755';
Expand All @@ -13,48 +28,17 @@

# TODO: update times listed here after move to remote backups

# Since we use sync_first, actual backups only happen at the most frequent
# ("smallest") backup level, i.e. daily.
#
# The other backup levels just promote a daily backup into a weekly/monthly
# one, so they are comparatively fast.
#
# As of 2015-03-29, it takes 30 minutes to do a promotion, and 4 hours to do
# a full backup. So we leave 2 hours for promotions and 8 hours for a full
# backup to be safe.
#
# It's important that jobs don't overlap, so our plan is:
# 10pm-12am monthly backup takes place (~30 minutes)
# 12am-2am: weekly backup takes place (~30 minutes)
# 2am-10am: daily backup takes place (~4 hours)

$rsnapshot = 'rsnapshot -c /opt/share/backups/rsnapshot.conf'
$rsnapshot = '/usr/local/sbin/backup-zfs.sh | tee -a /var/log/zfs-backup.log'

cron {
default:
user => root,
minute => '0';

# 10pm on 1st of month
'rsnapshot-monthly':
command => "${rsnapshot} monthly",
hour => '22',
monthday => '1';

# 12am Saturday mornings
'rsnapshot-weekly':
command => "${rsnapshot} weekly",
hour => '0',
weekday => '6';

# 2am daily
# ZFS
'rsnapshot-daily':
command => "${rsnapshot} sync && ${rsnapshot} daily",
hour => '2';

# check rsnapshot backups to ensure they're actually happening
'check-rsnapshot-backups':
command => '/opt/share/backups/check-rsnapshot-backups',
hour => '10';
command => $rsnapshot,
hour => '03',
minute => '00';
}
}