add backup job
This commit is contained in:
parent
1592aaff89
commit
473baa9b95
|
@ -2,16 +2,24 @@ class BackupServer
|
||||||
@queue = :high
|
@queue = :high
|
||||||
|
|
||||||
def self.perform()
|
def self.perform()
|
||||||
#CronMail.time_check("Going to backup Orbit").deliver
|
|
||||||
dbhost = Mongoid.config.database.connection.primary.join ':'
|
dbhost = Mongoid.config.database.connection.primary.join ':'
|
||||||
dbname = Mongoid.config.database.name
|
dbname = Mongoid.config.database.name
|
||||||
archive_db_list_path = OrbitSystemPreference::ArchiveDbListPath
|
archive_db_list_path = OrbitSystemPreference::ArchiveDbListPath
|
||||||
dbdirectory = "#{Rails.root}/tmp/#{dbname}-"+Time.now.strftime("%Y-%m-%d-%H-%M")
|
dbdirectory = "#{Rails.root}/tmp/#{dbname}-"+Time.now.strftime("%Y-%m-%d-%H-%M")
|
||||||
%x[mongodump -h #{dbhost} -d #{dbname} -o #{dbdirectory} ]
|
%x[mongodump -h #{dbhost} -d #{dbname} -o #{dbdirectory} ]
|
||||||
|
|
||||||
%x[rm #{archive_db_list_path}]
|
Dir.foreach('tmp') do |item|
|
||||||
%x[ls #{Rails.root}/tmp/#{dbname}* | du -h --max-depth=1 --block-size=1M |sort -h >> #{archive_db_list_path}]
|
date_str = item.to_s.gsub("#{dbname}-",'')
|
||||||
OrbitLogger.info "DB backup done Path:#{dbdirectory}"
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Site
|
||||||
field :title, localize: true
|
field :title, localize: true
|
||||||
field :footer, localize: true
|
field :footer, localize: true
|
||||||
field :sub_menu, 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
|
field :mobile_on, :type => Boolean, :default => false
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ defaults: &defaults
|
||||||
store_ip: 'redmine.rulingcom.com:3001'
|
store_ip: 'redmine.rulingcom.com:3001'
|
||||||
orbit: 'Orbit'
|
orbit: 'Orbit'
|
||||||
ruling_digital: 'RulingDigital'
|
ruling_digital: 'RulingDigital'
|
||||||
|
backup_keep_for_days: 30
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
|
|
@ -4,6 +4,12 @@ dashboard_counter_cache:
|
||||||
args:
|
args:
|
||||||
description: DashboardCounterCache
|
description: DashboardCounterCache
|
||||||
|
|
||||||
|
backup_server:
|
||||||
|
cron: 0 0 2 * * *
|
||||||
|
class: BackupServer
|
||||||
|
args:
|
||||||
|
description: BackupServer and remove old backups
|
||||||
|
|
||||||
update_tag_cloud:
|
update_tag_cloud:
|
||||||
cron: 0 0 [0,12] * * *
|
cron: 0 0 [0,12] * * *
|
||||||
class: UpdateTagCloud
|
class: UpdateTagCloud
|
||||||
|
|
Loading…
Reference in New Issue