Skip to content

Instantly share code, notes, and snippets.

@yingziwu
Last active March 26, 2019 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yingziwu/b976e56115f08bda5998152186de733a to your computer and use it in GitHub Desktop.
Save yingziwu/b976e56115f08bda5998152186de733a to your computer and use it in GitHub Desktop.
backup mastodon
#!/bin/bash
umask 027
# 创建临时目录
BACKUP_TIME=$(date +%s)
BACKUP_DIR=/tmp/backup/mstdn/mstdn_${BACKUP_TIME}_$RANDOM
[ -e ${BACKUP_DIR} ] || mkdir -p ${BACKUP_DIR}
# 生成加密密钥
PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 30)
echo $PASSWORD | gpg --recipient 238941C66CC382E5 --encrypt --armor --trust-model always --output $BACKUP_DIR/key.asc
# 备份加密数据库
pg_dump -d mastodon_production | 7z a -si -p${PASSWORD} $BACKUP_DIR/db.sql.7z
# 上传备份
aws s3 sync /tmp/backup/ s3://mstdn-backup/ --endpoint-url=https://s3.us-west-1.wasabisys.com
# 收尾
rm -rf ${BACKUP_DIR}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::mstdn-backup"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::mstdn-backup/*"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment