Backup database to S3
This commit is contained in:
parent
ae0c5392b7
commit
5cc81b167a
@ -12,6 +12,17 @@ let
|
||||
"chocobozzz/peertube@" +
|
||||
"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";
|
||||
hostName = builtins.replaceStrings [ "." ] [ "-" ] "${domainName}";
|
||||
in {
|
||||
@ -156,6 +167,26 @@ in {
|
||||
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 = {
|
||||
enable = true;
|
||||
bind = "127.0.0.1";
|
||||
|
@ -3,6 +3,15 @@
|
||||
""
|
||||
];
|
||||
|
||||
backup = {
|
||||
password = "";
|
||||
accessKey = "";
|
||||
secretKey = "";
|
||||
host = "";
|
||||
hostBucket = "";
|
||||
bucket = "";
|
||||
};
|
||||
|
||||
peertube = {
|
||||
secret = "";
|
||||
db = {
|
||||
|
Loading…
Reference in New Issue
Block a user