Duplicity 和 Amazon S3 脚本

Duplicity 和 Amazon S3 脚本

我希望使用 duplicity 将我的 Linux 服务器备份到 Amazon S3。

我发现了一个很棒的资源在这里它帮助我进行设置,并使用那里列出的、现在已复制到此处的基本脚本:

#!/bin/sh
# Export some ENV variables so you don't have to type anything
export AWS_ACCESS_KEY_ID=[your-access-key-id]
export AWS_SECRET_ACCESS_KEY=[your-secret-access-key]
export PASSPHRASE=[your-gpg-passphrase]

GPG_KEY=[your-gpg-key]

# The source of your backup
SOURCE=/

# The destination
# Note that the bucket need not exist
# but does need to be unique amongst all
# Amazon S3 users. So, choose wisely.
DEST=s3+http://[your-bucket-name]/[backup-folder]

duplicity \
    --encrypt-key=${GPG_KEY} \
    --sign-key=${GPG_KEY} \
    --include=/boot \
    --include=/etc \
    --include=/home \
    --include=/root \
    --include=/var/lib/mysql \
    --exclude=/** \
    ${SOURCE} ${DEST}

# Reset the ENV variables. Don't need them sitting around
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export PASSPHRASE=

是否有其他人有使用 duplicity 的经验,他们可以改进这个脚本和/或分享最佳实践来帮助创建更好的脚本?

答案1

我正在使用该脚本的变体进行备份。我最近对其进行了一些更改,以尝试节省一些 Amazon S3 账单费用(个人服务器,否则我不会那么介意)。

完整脚本如下这里,但我会在下面列出我所做的更改。

--full-if-older-than 1M
--volsize 250

第一个选项确保 duplicity 每月都会进行一次完整备份。这很有用,因为这意味着如果我需要从 S3 中删除文件,我可以删除最新的完整备份。

第二种选择是减少 Duplicity 在 S3 上存储的文件数量,从而减少对 S3 发出的请求数量,降低成本。

备份运行后,我还添加了以下内容。这将从 S3 中删除所有超过 6 个月的备份。

duplicity remove-older-than 6M --force ${DEST}

相关内容