Skip to content

Commit

Permalink
use timestamp in backup file name
Browse files Browse the repository at this point in the history
to avoid possible rewriting an old backup
  • Loading branch information
lslezak committed Jun 2, 2014
1 parent 6e7f74b commit cbe66f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/clients/inst_scc.rb
Expand Up @@ -198,7 +198,11 @@ def show_registration_update_dialog
def update_registration
show_registration_update_dialog

# prepare the target system for upgrade
::Registration::SwMgmt.prepare_for_upgrade!(Installation.destdir)

if refresh_base_product
# TODO FIXME: refresh also the addons
return :next
else
# automatic registration refresh during system upgrade failed, register from scratch
Expand Down
5 changes: 3 additions & 2 deletions src/lib/registration/sw_mgmt.rb
Expand Up @@ -80,11 +80,12 @@ def self.zypp_config_writable!
end

def self.backup(root_dir)
::FileUtils.mkdir_p(File.join(root_dir, File.dirname(BACKUP_FILE)))
time_stamp = Time.now.localtime.strftime("%Y%m%d-%H%M%S")
target_file = File.join(root_dir, "/var/adm/backup/upgrade/sw_mgmt-#{time_stamp}.tar.gz")
::FileUtils.mkdir_p(File.dirname(target_file))

backup_dirs = BACKUP_DIRS.select{|dir| File.exist?(File.join(root_dir, dir))}
backup_dirs.map!{|dir| File.join(root_dir, dir)}
target_file = File.join(root_dir, BACKUP_FILE)

log.info "Creating backup file #{target_file} with: #{backup_dirs}"

Expand Down
12 changes: 8 additions & 4 deletions test/sw_mgmt_spec.rb
Expand Up @@ -136,15 +136,19 @@
let(:root_dir) { "/mnt" }

before do
expect(FileUtils).to receive(:mkdir_p).with(File.join(root_dir, File.dirname(Registration::SwMgmt::BACKUP_FILE)))
expect(FileUtils).to receive(:mkdir_p).with("#{root_dir}/var/adm/backup/upgrade")

Registration::SwMgmt::BACKUP_DIRS.each do |dir|
expect(File).to receive(:exist?).with(File.join(root_dir, dir)).and_return(true)
end

expect(Registration::SwMgmt).to receive(:`).with(
"tar cfzv #{root_dir}/var/adm/backup/upgrade/sw_mgmt.tar.gz #{root_dir}/etc/zypp/repos.d " \
"#{root_dir}/etc/zypp/services.d #{root_dir}/etc/zypp/credentials.d")
expect(Registration::SwMgmt).to receive(:`) do |param|
expect(param).to match(/tar\scfzv\s
#{root_dir}\/var\/adm\/backup\/upgrade\/sw_mgmt-.*\.tar\.gz\s
#{root_dir}\/etc\/zypp\/repos.d\s
#{root_dir}\/etc\/zypp\/services.d\s
#{root_dir}\/etc\/zypp\/credentials.d/x)
end

File.stub_chain(:stat, :size => 42)
end
Expand Down

0 comments on commit cbe66f0

Please sign in to comment.