Backup database to S3

This commit is contained in:
dump_stack() 2023-01-17 17:20:56 +00:00
parent ae0c5392b7
commit 5cc81b167a
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 40 additions and 0 deletions

View File

@ -12,6 +12,17 @@ let
"chocobozzz/peertube@" + "chocobozzz/peertube@" +
"sha256:3bd126fc8b66a6a12593d73f74d0a3ffc7fc3206e5e9ebf39c8a8e0ca5408194"; "sha256:3bd126fc8b66a6a12593d73f74d0a3ffc7fc3206e5e9ebf39c8a8e0ca5408194";
s3cmd = pkgs.writeShellScript "s3cmd" ''
${pkgs.s3cmd}/bin/s3cmd \
--access_key='${secrets.backup.accessKey}' \
--secret_key='${secrets.backup.secretKey}' \
--host='${secrets.backup.host}' \
--host-bucket='${secrets.backup.hostBucket}' \
$@
'';
bucket = secrets.backup.bucket;
domainName = "v.lor.sh"; domainName = "v.lor.sh";
hostName = builtins.replaceStrings [ "." ] [ "-" ] "${domainName}"; hostName = builtins.replaceStrings [ "." ] [ "-" ] "${domainName}";
in { in {
@ -156,6 +167,26 @@ in {
enableTCPIP = true; enableTCPIP = true;
}; };
services.postgresqlBackup = {
enable = true;
databases = [ "peertube" ];
compression = "gzip";
};
systemd.services.postgresqlBackup-peertube.serviceConfig.ExecStartPost =
pkgs.writeShellScript "backup-to-s3" ''
cd /var/backup/postgresql
${pkgs.gnupg}/bin/gpg --batch --passphrase '${secrets.backup.password}' \
--symmetric peertube.sql.gz
${s3cmd} rm ${bucket}/peertube.prev.sql.gz.gpg
${s3cmd} mv ${bucket}/peertube.sql.gz.gpg ${bucket}/peertube.prev.sql.gz.gpg
${s3cmd} put peertube.sql.gz.gpg ${bucket}/
rm peertube.sql.gz.gpg
'';
services.redis.servers.peertube = { services.redis.servers.peertube = {
enable = true; enable = true;
bind = "127.0.0.1"; bind = "127.0.0.1";

View File

@ -3,6 +3,15 @@
"" ""
]; ];
backup = {
password = "";
accessKey = "";
secretKey = "";
host = "";
hostBucket = "";
bucket = "";
};
peertube = { peertube = {
secret = ""; secret = "";
db = { db = {