summaryrefslogtreecommitdiffstats
path: root/ipaserver
diff options
context:
space:
mode:
authorMartin Basti <mbasti@redhat.com>2015-09-10 16:35:54 +0200
committerMartin Basti <mbasti@redhat.com>2015-09-11 14:57:58 +0200
commitf8f5bd644aee5c54acc857061868e659ae449e48 (patch)
treeab2c00798fb7ebf3c4f4e61e5c7a2dbbf1a66573 /ipaserver
parent5762ad951fca025f17d00095bd7d89a14536ae85 (diff)
downloadfreeipa-f8f5bd644aee5c54acc857061868e659ae449e48.tar.gz
freeipa-f8f5bd644aee5c54acc857061868e659ae449e48.tar.xz
freeipa-f8f5bd644aee5c54acc857061868e659ae449e48.zip
IPA Restore: allows to specify files that should be removed
Some files/directories should be removed before backup files are copied to filesystem. In case of DNSSEC, the /var/lib/ipa/dnssec/tokens directory has to be removed, otherwise tokens that are backed up and existing tokens will be mixed and SOFTHSM log in will not work https://fedorahosted.org/freeipa/ticket/5293 Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipaserver')
-rw-r--r--ipaserver/install/ipa_restore.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
index e8820b99e..b7af88d99 100644
--- a/ipaserver/install/ipa_restore.py
+++ b/ipaserver/install/ipa_restore.py
@@ -128,6 +128,14 @@ class Restore(admintool.AdminTool):
description = "Restore IPA files and databases."
+ # directories and files listed here will be removed from filesystem before
+ # files from backup are copied
+ DIRS_TO_BE_REMOVED = [
+ paths.DNSSEC_TOKENS_DIR,
+ ]
+
+ FILES_TO_BE_REMOVED = []
+
def __init__(self, options, args):
super(Restore, self).__init__(options, args)
self._conn = None
@@ -365,6 +373,7 @@ class Restore(admintool.AdminTool):
# We do either a full file restore or we restore data.
if restore_type == 'FULL':
+ self.remove_old_files()
if 'CA' in self.backup_services:
create_ca_user()
self.cert_restore_prepare()
@@ -647,6 +656,25 @@ class Restore(admintool.AdminTool):
(paths.IPA_DEFAULT_CONF, stderr))
os.chdir(cwd)
+ def remove_old_files(self):
+ """
+ Removes all directories, files or temporal files that should be
+ removed before backup files are copied, to prevent errors.
+ """
+ for d in self.DIRS_TO_BE_REMOVED:
+ try:
+ shutil.rmtree(d)
+ except OSError as e:
+ if e.errno != 2: # 2: dir does not exist
+ self.log.warning("Could not remove directory: %s (%s)",
+ d, e)
+
+ for f in self.FILES_TO_BE_REMOVED:
+ try:
+ os.remove(f)
+ except OSError as e:
+ if e.errno != 2: # 2: file does not exist
+ self.log.warning("Could not remove file: %s (%s)", f, e)
def file_restore(self, nologs=False):
'''