pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0119-IPA-Restore-allows-to-specify-files-that-should-be-r.patch

590d18
From 98e289720cbe58e2d921ee95d316644c1bb5cce8 Mon Sep 17 00:00:00 2001
590d18
From: Martin Basti <mbasti@redhat.com>
590d18
Date: Thu, 10 Sep 2015 16:35:54 +0200
590d18
Subject: [PATCH] IPA Restore: allows to specify files that should be removed
590d18
590d18
Some files/directories should be removed before backup files are copied
590d18
to filesystem.
590d18
590d18
In case of DNSSEC, the /var/lib/ipa/dnssec/tokens directory has to be
590d18
removed, otherwise tokens that are backed up and existing tokens will be
590d18
mixed and SOFTHSM log in will not work
590d18
590d18
https://fedorahosted.org/freeipa/ticket/5293
590d18
590d18
Reviewed-By: David Kupka <dkupka@redhat.com>
590d18
---
590d18
 ipaserver/install/ipa_restore.py | 28 ++++++++++++++++++++++++++++
590d18
 1 file changed, 28 insertions(+)
590d18
590d18
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
590d18
index 8960626d0f0e438ef198e2d92803983e520051a8..dc57a4937365ad1db960955cf21e1bf2d2eb3dda 100644
590d18
--- a/ipaserver/install/ipa_restore.py
590d18
+++ b/ipaserver/install/ipa_restore.py
590d18
@@ -128,6 +128,14 @@ class Restore(admintool.AdminTool):
590d18
 
590d18
     description = "Restore IPA files and databases."
590d18
 
590d18
+    # directories and files listed here will be removed from filesystem before
590d18
+    # files from backup are copied
590d18
+    DIRS_TO_BE_REMOVED = [
590d18
+        paths.DNSSEC_TOKENS_DIR,
590d18
+    ]
590d18
+
590d18
+    FILES_TO_BE_REMOVED = []
590d18
+
590d18
     def __init__(self, options, args):
590d18
         super(Restore, self).__init__(options, args)
590d18
         self._conn = None
590d18
@@ -365,6 +373,7 @@ class Restore(admintool.AdminTool):
590d18
 
590d18
             # We do either a full file restore or we restore data.
590d18
             if restore_type == 'FULL':
590d18
+                self.remove_old_files()
590d18
                 if 'CA' in self.backup_services:
590d18
                     create_ca_user()
590d18
                 self.cert_restore_prepare()
590d18
@@ -640,6 +649,25 @@ class Restore(admintool.AdminTool):
590d18
                               (paths.IPA_DEFAULT_CONF, stderr))
590d18
         os.chdir(cwd)
590d18
 
590d18
+    def remove_old_files(self):
590d18
+        """
590d18
+        Removes all directories, files or temporal files that should be
590d18
+        removed before backup files are copied, to prevent errors.
590d18
+        """
590d18
+        for d in self.DIRS_TO_BE_REMOVED:
590d18
+            try:
590d18
+                shutil.rmtree(d)
590d18
+            except OSError as e:
590d18
+                if e.errno != 2:  # 2: dir does not exist
590d18
+                    self.log.warning("Could not remove directory: %s (%s)",
590d18
+                                     d, e)
590d18
+
590d18
+        for f in self.FILES_TO_BE_REMOVED:
590d18
+            try:
590d18
+                os.remove(f)
590d18
+            except OSError as e:
590d18
+                if e.errno != 2:  # 2: file does not exist
590d18
+                    self.log.warning("Could not remove file: %s (%s)", f, e)
590d18
 
590d18
     def file_restore(self, nologs=False):
590d18
         '''
590d18
-- 
590d18
2.4.3
590d18