* refactor aws config options

* fix aws calls in savedsearch
* remove unused scripts
This commit is contained in:
r888888888
2015-12-28 12:25:38 -08:00
parent 811a60bb9d
commit d5fa4b46e3
9 changed files with 108 additions and 139 deletions

View File

@@ -1,3 +0,0 @@
#!/bin/bash
PGOPTIONS="-c statement_timeout=0" pg_dump -Fc -hdbserver -f /var/www/danbooru2/shared/backup/db-`date +"%Y-%m-%d-%H-%M"`.dump danbooru2

View File

@@ -1,55 +0,0 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk/s3'
MAX_BACKUPS = 30
home = File.expand_path("~")
if !File.exists?("#{home}/.s3/access_key")
STDERR.puts "Access key not found"
exit 1
end
if !File.exists?("#{home}/.s3/secret_access_key")
STDERR.puts "Secret access key not found"
exit 1
end
access_key = open("#{home}/.s3/access_key").read.strip
secret_access_key = open("#{home}/.s3/secret_access_key").read.strip
credentials = Aws::Credentials.new(Danbooru.config.amazon_s3_access_key_id, Danbooru.config.amazon_s3_secret_access_key)
Aws.config.update({
region: "us-east-1",
credentials: credentials
})
client = Aws::S3::Client.new
bucket = "danbooru-backup"
current_backups = client.list_objects(buckets: buckets).contents.map {|x| x.key}.select {|x| x =~ /^db-/}.sort.reverse
if current_backups.size > MAX_BACKUPS
current_backups[MAX_BACKUPS..-1].each do |old_backup|
client.delete_object(bucket: bucket, key: old_backup)
puts "Deleted old backup #{old_backup}"
end
end
backup = Dir["/var/www/danbooru2/shared/backup/db-*.dump"].sort.last
data = File.open(backup, "rb")
filename = data.mtime.strftime("db-%Y-%m-%d-%H-%M")
tries = 0
begin
client.put_object(bucket: bucket, key: filename, body: data, :acl => "private")
rescue Errno::EPIPE
tries += 1
if tries > 3
raise
else
retry
end
end
puts "Uploaded #{backup} as #{filename}"

View File

@@ -1,3 +0,0 @@
#!/bin/bash
find /var/www/danbooru2/shared/backup -name 'db-*.dump' -mtime +30 -exec /bin/rm -f {} \;