Elastic Beanstalk - SQLite 数据库

fig*_*r20 4 sqlite amazon-s3 amazon-ec2 amazon-web-services amazon-elastic-beanstalk

我有一个简单的 javascript 网站,托管在 Elastic Beanstalk 上。该应用程序的一部分使用 SQLite 数据库来处理日志记录和分析。

每当将站点的新版本部署到 Elastic Beanstalk 实例时,它都会破坏以前的版本,从而导致我丢失 SQLite 数据库的内容。

有人对这个问题有任何解决方案吗?将 SQLite 数据库存储在 S3 存储桶中是否有效?

我知道我可以使用 RDS 数据库,但我试图避免重写我的代码。

Sam*_* H. 5

是的,备份到 S3 很有意义。您可以使用平台挂钩来几乎优雅地完成此操作。在应用程序的根目录中创建一个.ebextensions目录,并在其中创建一个名为sqlite_backup.conf

\n\n
files:\n  /opt/elasticbeanstalk/hooks/preinit/01_sqlite_backup.sh:\n    mode: "000755"\n    owner: root\n    group: root\n    content: |\n      #!/bin/sh\n      # insert shell script which backs up sqlite to s3, something like the following:\n      # set backup directory variables\n      SRCDIR=\'/tmp/s3backups\'\n      DESTDIR=\'path/to/s3folder\'\n      BUCKET=\'s3bucket\'\n      NOWDATE=`date +%Y-%m-%d`\n      sqlite3 test.db \xe2\x80\x98.dump\xe2\x80\x99 > $SRCDIR/dbbackup\n      cd $SRCDIR\n      tar -czPf $NOWDATE-backup.tar.gz dbbackup\n      # upload backup to s3\n      /usr/bin/s3cmd put $SRCDIR/$NOWDATE-backup.tar.gz s3://$BUCKET/$DESTDIR/\n      # 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).\n
Run Code Online (Sandbox Code Playgroud)\n\n

还有一个叫sqlite_restore.conf

\n\n
files:\n  /opt/elasticbeanstalk/hooks/postinit/99_sqlite_restore.sh:\n    mode: "000755"\n    owner: root\n    group: root\n    content: |\n      #!/bin/sh\n      # insert shell script which restores sqlite from s3\n
Run Code Online (Sandbox Code Playgroud)\n\n

由于他们的安置/opt/elasticbeanstalk/hooks/(pre|post)init它们将在正确的时间运行。这些文件按文件名的字母顺序执行,因此是我选择的名称。

\n\n

用于将数据库备份到 S3 的良好 shell 脚本: https ://github.com/lumerit/s3-shell-backups

\n