0

我正在使用 s3cmd 将我的数据库备份到 Amazon S3,但我还想备份某个文件夹并将其存档。

我有这个脚本的这一部分,它成功地将数据库备份到 S3:

# Loop the databases
for db in $databases; do

  # Define our filenames
  filename="$stamp - $db.sql.gz"
  tmpfile="/tmp/$filename"
  object="$bucket/$stamp/$filename"

  # Feedback
  echo -e "\e[1;34m$db\e[00m"

  # Dump and zip
  echo -e "  creating \e[0;35m$tmpfile\e[00m"
  mysqldump -u root -p$mysqlpass --force --opt --databases "$db" | gzip -c > "$tmpfile"

  # Upload
  echo -e "  uploading..."
  s3cmd put "$tmpfile" "$object"

  # Delete
  rm -f "$tmpfile"

done;

如何添加另一个部分来存档某个文件夹,上传到 S3 然后删除本地存档?

4

1 回答 1

0

未经测试和基本的,但这应该通过一些小的调整来完成工作

# change to tmp dir - creating archives with absolute paths can be dangerous
cd /tmp

# create archive with timestamp of dir /path/to/directory/to/archive
tar -czf "$stamp-archivename.tar.gz" /path/to/directory/to/archive

# upload archive to s3 bucket 'BucketName'
s3cmd put "/tmp/$stamp-archivename.tar.gz" s3://BucketName/

# remove local archive
rm -f "/tmp/$stamp-archivename.tar.gz"
于 2014-07-30T13:29:56.317 回答