platform hooks
这样做几乎优雅。创建
.ebextensions
在你的应用程序的根目录中,并在其中创建一个名为
sqlite_backup.conf
:
files:
/opt/elasticbeanstalk/hooks/preinit/01_sqlite_backup.sh:
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
# insert shell script which backs up sqlite to s3, something like the following:
# set backup directory variables
SRCDIR='/tmp/s3backups'
DESTDIR='path/to/s3folder'
BUCKET='s3bucket'
NOWDATE=`date +%Y-%m-%d`
sqlite3 test.db â.dumpâ > $SRCDIR/dbbackup
cd $SRCDIR
tar -czPf $NOWDATE-backup.tar.gz dbbackup
# upload backup to s3
/usr/bin/s3cmd put $SRCDIR/$NOWDATE-backup.tar.gz s3://$BUCKET/$DESTDIR/
# check if these persist across deploys - they shouldn't, but if they do, you don't have to backup to S3 (you also have to worry about filling up the disk).
另一个叫
sqlite_restore.conf
:
files:
/opt/elasticbeanstalk/hooks/postinit/99_sqlite_restore.sh:
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
# insert shell script which restores sqlite from s3
因为他们的位置
/opt/elasticbeanstalk/hooks/(pre|post)init
他们将在正确的时间运行。文件是按文件名的字母顺序执行的,因此我选择了名称。
将DBs备份到S3的很好的shell脚本:
https://github.com/lumerit/s3-shell-backups