use object storage directory instead of tar
This commit is contained in:
parent
3aff383a2c
commit
983f47440f
1 changed files with 11 additions and 14 deletions
25
backup.nix
25
backup.nix
|
@ -10,9 +10,8 @@ let
|
||||||
user = "misskey-backup";
|
user = "misskey-backup";
|
||||||
group = user;
|
group = user;
|
||||||
|
|
||||||
# shell script file to be sourced. must have values "MISSKEY_BACKUP_BUCKET" "MISSKEY_BACKUP_PREFIX" and "S3CFG"
|
|
||||||
# $S3CFG must be a path to a .s3cfg file compatible with s3cmd
|
|
||||||
backupConfigFile = "/etc/misskey-backup/conf";
|
backupConfigFile = "/etc/misskey-backup/conf";
|
||||||
|
s3Cfg = "/etc/misskey-backup/s3cfg";
|
||||||
backupScript = pkgs.writeShellApplication {
|
backupScript = pkgs.writeShellApplication {
|
||||||
name = "misskey-backup";
|
name = "misskey-backup";
|
||||||
|
|
||||||
|
@ -27,24 +26,22 @@ let
|
||||||
excludeShellChecks = [ "SC1091" ];
|
excludeShellChecks = [ "SC1091" ];
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
source "${backupConfigFile}"
|
bucket="$(cat "${backupConfigFile}" | grep 'bucket=' | sed 's/bucket \?= \?')"
|
||||||
|
prefix="$(cat "${backupConfigFile}" | grep 'prefix=' | sed 's/prefix \?= \?')"
|
||||||
|
|
||||||
dir="$(mktemp --directory)"
|
s3Dir="s3://$bucket/\$\{prefix}misskey-$(date --iso-8601)"
|
||||||
echo "Using temp dir '$dir'"
|
echo "Uploading backups to '$s3Dir'"
|
||||||
|
|
||||||
trap EXIT "rm -rf '$dir'"
|
echo "Uploading config"
|
||||||
|
tar -cz -C /srv/misskey/.config . | s3cmd put --config "${s3Cfg}" - "$s3Dir/config.tar.gz"
|
||||||
echo "Copying config"
|
|
||||||
cp /srv/misskey/.config "$dir/config" -r
|
|
||||||
|
|
||||||
echo "Dumping postgres database..."
|
echo "Dumping postgres database..."
|
||||||
pg_dump misskey | gzip > "$dir/postgres.sql.gz"
|
pg_dump misskey | gzip | s3cmd put --config "${s3Cfg}" - "$s3Dir/pg_dump.sql.gz"
|
||||||
|
|
||||||
echo "Copying redis database..."
|
echo "Uploading redis database..."
|
||||||
cp /var/lib/redis-misskey "$dir/redis" -r
|
tar -cz -C /var/lib/redis-misskey . | s3cmd put --config "${s3Cfg}" - "$s3Dir/redis.tar.gz"
|
||||||
|
|
||||||
tar -cz -C "$dir" . | \
|
echo "Backup complete to '$s3Dir'"
|
||||||
s3cmd put --config "$S3CFG" - "s3://$MISSKEY_BACKUP_BUCKET/\$\{MISSKEY_BACKUP_PREFIX}misskey-$(date --iso-8601).tar.gz"
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
|
|
Loading…
Reference in a new issue