diff --git a/app/jobs/backup_server.rb b/app/jobs/backup_server.rb index 0010b51fe..c099ef9d6 100644 --- a/app/jobs/backup_server.rb +++ b/app/jobs/backup_server.rb @@ -2,16 +2,24 @@ class BackupServer @queue = :high def self.perform() - #CronMail.time_check("Going to backup Orbit").deliver dbhost = Mongoid.config.database.connection.primary.join ':' dbname = Mongoid.config.database.name archive_db_list_path = OrbitSystemPreference::ArchiveDbListPath dbdirectory = "#{Rails.root}/tmp/#{dbname}-"+Time.now.strftime("%Y-%m-%d-%H-%M") %x[mongodump -h #{dbhost} -d #{dbname} -o #{dbdirectory} ] - %x[rm #{archive_db_list_path}] - %x[ls #{Rails.root}/tmp/#{dbname}* | du -h --max-depth=1 --block-size=1M |sort -h >> #{archive_db_list_path}] + Dir.foreach('tmp') do |item| + date_str = item.to_s.gsub("#{dbname}-",'') + next if not date_str.match(/\d{4}-\d{2}-\d{2}-\d{2}-\d{2}/) + if Date.parse(date_str).to_time < Site.first.backup_keep_for_days.days.ago + OrbitLogger.info "Deleting #{date_str}" + %x[rm -rf tmp/#{item}] + end + end + + + %x[rm -f #{archive_db_list_path}] + %x[cd tmp ; ls -l |grep #{dbname} | awk '{print $8}'|xargs du -h --block-size=1M --max-depth=0 |sort -h >> #{archive_db_list_path}] OrbitLogger.info "DB backup done Path:#{dbdirectory}" - end end diff --git a/app/models/site.rb b/app/models/site.rb index 13a1cee6f..bbb2cbe50 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -33,6 +33,7 @@ class Site field :title, localize: true field :footer, localize: true field :sub_menu, localize: true + field :backup_keep_for_days,:type=>Integer,:default=> APP_CONFIG['backup_keep_for_days'] field :mobile_on, :type => Boolean, :default => false diff --git a/config/config.yml b/config/config.yml index 439386fb1..4e008ba2a 100644 --- a/config/config.yml +++ b/config/config.yml @@ -3,6 +3,7 @@ defaults: &defaults store_ip: 'redmine.rulingcom.com:3001' orbit: 'Orbit' ruling_digital: 'RulingDigital' + backup_keep_for_days: 30 development: <<: *defaults diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index b91d40a2a..83f580122 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -4,6 +4,12 @@ dashboard_counter_cache: args: description: DashboardCounterCache +backup_server: + cron: 0 0 2 * * * + class: BackupServer + args: + description: BackupServer and remove old backups + update_tag_cloud: cron: 0 0 [0,12] * * * class: UpdateTagCloud