Re: [Freeipa-devel] [PATCH 0313] IPA Restore: allow to specify dirs/files which should be removed before restore

2015-09-11 Thread Martin Basti



On 09/11/2015 02:56 PM, David Kupka wrote:

On 11/09/15 14:44, Martin Basti wrote:



On 09/10/2015 05:34 PM, Martin Basti wrote:

https://fedorahosted.org/freeipa/ticket/5293

Patch attached.




Updated patch attached.

* list of dirs/files was moved to class (the same way is in ipa-backup)
* log errors if dir/file cannot be removed (errors other than dir/file
does not exist)


Looks good to me and works as expected, ACK.


Pushed to:
master: f8f5bd644aee5c54acc857061868e659ae449e48
ipa-4-2: 21f2a3d1731a43551cc130356329bcadba7ffdfe

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] [PATCH 0313] IPA Restore: allow to specify dirs/files which should be removed before restore

2015-09-11 Thread Martin Basti



On 09/10/2015 05:34 PM, Martin Basti wrote:

https://fedorahosted.org/freeipa/ticket/5293

Patch attached.




Updated patch attached.

* list of dirs/files was moved to class (the same way is in ipa-backup)
* log errors if dir/file cannot be removed (errors other than dir/file 
does not exist)
From 43c339ea20404347fd58a34597ac69c99d674745 Mon Sep 17 00:00:00 2001
From: Martin Basti 
Date: Thu, 10 Sep 2015 16:35:54 +0200
Subject: [PATCH] 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
---
 ipaserver/install/ipa_restore.py | 28 
 1 file changed, 28 insertions(+)

diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
index e8820b99ede4bb8eaa95bb8f25d946cb369f3048..b7af88d99e0e291ea086cf64c410e9a2f10aefaf 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):
 '''
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code