add backup job
This commit is contained in:
parent
1592aaff89
commit
473baa9b95
|
@ -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}]
|
||||
OrbitLogger.info "DB backup done Path:#{dbdirectory}"
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ defaults: &defaults
|
|||
store_ip: 'redmine.rulingcom.com:3001'
|
||||
orbit: 'Orbit'
|
||||
ruling_digital: 'RulingDigital'
|
||||
backup_keep_for_days: 30
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue