我们也用的 cron,传到 s3,代码 1 年前的,可能过时了,没升级 Fog 什么的 gem,不过一直很稳定没出错过
desc"Backup the database to Amazon S3"task:backup=>:dumpdotimestamp=Time.now.strftime('%Y_%m_%d_%H_%M_%S')backup_filename="#{Rails.env}_dump_#{timestamp}.sql.gz"sql_file="#{Rails.root}/db/data/#{Rails.env}_dump.sql"Zlib::GzipWriter.open("#{Rails.root}/db/data/#{backup_filename}")do|gz|gz.writeFile.read(sql_file)endstorage=Fog::Storage.new(:provider=>'AWS',:aws_access_key_id=>APP_CONFIG['s3_access_key'],:aws_secret_access_key=>APP_CONFIG['s3_access_secret'])storage.put_object(APP_CONFIG['s3_backup_bucket'],backup_filename,File.read("#{Rails.root}/db/data/#{backup_filename}"),'x-amz-acl'=>'private')File.delete("#{Rails.root}/db/data/#{backup_filename}")# Clean up our leftoversend