def testBackupCertainFiles(self): os.mkdir(self.fs_root + "/subdir1") os.mkdir(self.fs_root + "/subdir1/subsubdir") os.mkdir(self.fs_root + "/subdir2") f=open(self.fs_root + "/subdir1/foo" , 'w') f.write("foo") f.close() f=open(self.fs_root + "/subdir2/bar" , 'w') f.write("bar") f.close() f=open(self.fs_root + "/subdir1/subsubdir/money" , 'w') f.write("money") f.close() backup_target = snap.backends.files.syum.Syum() backup_target.backup(self.basedir, include=[self.fs_root + "/subdir1"], exclude=[self.fs_root + "/subdir1/subsubdir"]) self.assertTrue(os.path.exists(self.basedir + self.fs_root + "/subdir1/foo")) self.assertFalse(os.path.exists(self.basedir + self.fs_root + "/subdir2/foo")) self.assertFalse(os.path.exists(self.basedir + self.fs_root + "/subdir1/subsubdir/money")) record = FilesRecordFile(self.basedir + "/files.xml") files = record.read() file_names = [] for sfile in files: file_names.append(sfile.path) self.assertEqual(1, len(files)) self.assertIn(self.fs_root[1:] + "/subdir1/foo", file_names) self.assertNotIn(self.fs_root[1:] + "/subdir2/bar", file_names) self.assertNotIn(self.fs_root[1:] + "/subdir1/subsubdir/bar", file_names)
def restore(self, basedir): dispatcher = Dispatcher.os_dispatcher() record_file = os.path.join(basedir, "service-http.xml") # if files record file isn't found, simply return if not os.path.isfile(record_file): return # stop the httpd service if already running if dispatcher.service_running(Httpd.DAEMON): dispatcher.stop_service(Httpd.DAEMON) # read files from the record file record = FilesRecordFile(record_file) sfiles = record.read() # restore those to their original locations for sfile in sfiles: sfile.copy_to(path_prefix=basedir) # ensure the various subdirs exists even if empty if OS.is_linux() and not os.path.isdir(os.path.join(Httpd.DOCUMENT_ROOT, "html")): os.mkdir(os.path.join(Httpd.DOCUMENT_ROOT, "html")) if OS.is_linux() and not os.path.isdir(os.path.join(Httpd.CONF_D, "logs")): os.mkdir(os.path.join(Httpd.CONF_D, "logs")) if OS.is_linux() and not os.path.isdir(os.path.join(Httpd.CONF_D, "run")): os.mkdir(os.path.join(Httpd.CONF_D, "run")) # start the httpd service dispatcher.start_service(Httpd.DAEMON)
def restore(self, basedir): dispatcher = Dispatcher.os_dispatcher() record_file = os.path.join(basedir, "service-http.xml") # if files record file isn't found, simply return if not os.path.isfile(record_file): return # stop the httpd service if already running if dispatcher.service_running(Httpd.DAEMON): dispatcher.stop_service(Httpd.DAEMON) # read files from the record file record = FilesRecordFile(record_file) sfiles = record.read() # restore those to their original locations for sfile in sfiles: sfile.copy_to(path_prefix=basedir) # ensure the various subdirs exists even if empty if OS.is_linux() and not os.path.isdir( os.path.join(Httpd.DOCUMENT_ROOT, "html")): os.mkdir(os.path.join(Httpd.DOCUMENT_ROOT, "html")) if OS.is_linux() and not os.path.isdir( os.path.join(Httpd.CONF_D, "logs")): os.mkdir(os.path.join(Httpd.CONF_D, "logs")) if OS.is_linux() and not os.path.isdir( os.path.join(Httpd.CONF_D, "run")): os.mkdir(os.path.join(Httpd.CONF_D, "run")) # start the httpd service dispatcher.start_service(Httpd.DAEMON)
def testBackupCertainFiles(self): os.mkdir(os.path.join(self.fs_root, "subdir1")) os.mkdir(os.path.join(self.fs_root, "subdir1", "subsubdir")) os.mkdir(os.path.join(self.fs_root, "subdir2")) f = open(os.path.join(self.fs_root, "subdir1", "foo"), 'w') f.write("foo") f.close() f = open(os.path.join(self.fs_root, "subdir2", "bar"), 'w') f.write("bar") f.close() f = open(os.path.join(self.fs_root, "subdir1", "subsubdir", "money"), 'w') f.write("money") f.close() backup_target = snap.backends.files.win.Win() backup_target.backup( self.basedir, include=[os.path.join(self.fs_root, "subdir1")], exclude=[os.path.join(self.fs_root, "subdir1", "subsubdir")]) self.assertTrue( os.path.exists( os.path.join( self.basedir, SFile.windows_path_escape( os.path.join(self.fs_root, "subdir1", "foo"))))) self.assertFalse( os.path.exists( os.path.join( self.basedir, SFile.windows_path_escape( os.path.join(self.fs_root, "subdir2", "foo"))))) self.assertFalse( os.path.exists( os.path.join( self.basedir, SFile.windows_path_escape( os.path.join(self.fs_root, "subdir1", "subsubdir", "money"))))) record = FilesRecordFile(os.path.join(self.basedir, "files.xml")) files = record.read() file_names = [] for sfile in files: file_names.append(sfile.path) self.assertEqual(1, len(files)) self.assertIn( SFile.windows_path_escape( os.path.join(self.fs_root, "subdir1", "foo")), file_names) self.assertNotIn( SFile.windows_path_escape( os.path.join(self.fs_root, "subdir2", "bar")), file_names) self.assertNotIn( SFile.windows_path_escape( os.path.join(self.fs_root, "subdir1", "subsubdir", "bar")), file_names)
def testBackupCertainFiles(self): os.mkdir(os.path.join(self.fs_root, "subdir1")) os.mkdir(os.path.join(self.fs_root, "subdir1", "subsubdir")) os.mkdir(os.path.join(self.fs_root, "subdir2")) f = open(os.path.join(self.fs_root, "subdir1", "foo"), "w") f.write("foo") f.close() f = open(os.path.join(self.fs_root, "subdir2", "bar"), "w") f.write("bar") f.close() f = open(os.path.join(self.fs_root, "subdir1", "subsubdir", "money"), "w") f.write("money") f.close() backup_target = snap.backends.files.win.Win() backup_target.backup( self.basedir, include=[os.path.join(self.fs_root, "subdir1")], exclude=[os.path.join(self.fs_root, "subdir1", "subsubdir")], ) self.assertTrue( os.path.exists( os.path.join(self.basedir, SFile.windows_path_escape(os.path.join(self.fs_root, "subdir1", "foo"))) ) ) self.assertFalse( os.path.exists( os.path.join(self.basedir, SFile.windows_path_escape(os.path.join(self.fs_root, "subdir2", "foo"))) ) ) self.assertFalse( os.path.exists( os.path.join( self.basedir, SFile.windows_path_escape(os.path.join(self.fs_root, "subdir1", "subsubdir", "money")) ) ) ) record = FilesRecordFile(os.path.join(self.basedir, "files.xml")) files = record.read() file_names = [] for sfile in files: file_names.append(sfile.path) self.assertEqual(1, len(files)) self.assertIn(SFile.windows_path_escape(os.path.join(self.fs_root, "subdir1", "foo")), file_names) self.assertNotIn(SFile.windows_path_escape(os.path.join(self.fs_root, "subdir2", "bar")), file_names) self.assertNotIn( SFile.windows_path_escape(os.path.join(self.fs_root, "subdir1", "subsubdir", "bar")), file_names )
def testBackupFiles(self): f=open(self.fs_root + "/foo" , 'w') f.write("foo") f.close() backup_target = snap.backends.files.syum.Syum() backup_target.backup(self.basedir, include=[self.fs_root]) self.assertTrue(os.path.exists(self.basedir + self.fs_root + "/foo")) record = FilesRecordFile(self.basedir + "/files.xml") files = record.read() file_names = [] for sfile in files: file_names.append(sfile.name) self.assertIn("foo", file_names) self.assertEqual(1, len(files))
def restore(self, basedir): """restore the files in the snapfile""" # if files record file isn't found, simply return if not os.path.isfile(basedir + "/files.xml"): return if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring files using apt backend"); # read files from the record file record = FilesRecordFile(basedir + "/files.xml") sfiles = record.read() # restore those to their original locations for sfile in sfiles: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring file " + sfile.path); sfile.copy_to(self.fs_root, basedir)
def restore(self, basedir): out = open(OSUtils.null_file(), 'w') record_file = os.path.join(basedir, "service-iis.xml") # if files record file isn't found, simply return if not os.path.isfile(record_file): return # stop the httpd service if already running if WindowsDispatcher.is_feature_enabled(Iis.WEBSERVER_FEATURE): WindowsDispatcher.disable_feature(Iis.WEBSERVER_FEATURE) # read files from the record file record = FilesRecordFile(record_file) sfiles = record.read() # restore those to their original locations for sfile in sfiles: try: sfile.copy_to(path_prefix=basedir) except IOError, e: pass # just silently ignore errors for now
def restore(self, basedir): """restore the files in the snapfile""" # if files record file isn't found, simply return if not os.path.isfile(os.path.join(basedir, "files.xml")): return if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring files on windows"); # read files from the record file record = FilesRecordFile(os.path.join(basedir, "files.xml")) sfiles = record.read() # restore those to their original locations for sfile in sfiles: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring file " + sfile.path); try: sfile.copy_to(self.fs_root, basedir) except: if snap.config.options.log_level_at_least('normal'): snap.callback.snapcallback.message("Failed to restore file " + sfile.path);
def restore(cls, basedir): dispatcher = Dispatcher.os_dispatcher() record_file = os.path.join(basedir, "service-asterisk.xml") # if files record file isn't found, simply return if not os.path.isfile(record_file): return # stop the service if already running if dispatcher.service_running(Asterisk.DAEMON): dispatcher.stop_service(Asterisk.DAEMON) # read files from the record file record = FilesRecordFile(record_file) sfiles = record.read() # restore those to their original locations for sfile in sfiles: sfile.copy_to(path_prefix=basedir) # start the service dispatcher.start_service(Asterisk.DAEMON)
def restore(self, basedir): """restore the files in the snapfile""" # if files record file isn't found, simply return if not os.path.isfile(os.path.join(basedir, "files.xml")): return if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring files on windows") # read files from the record file record = FilesRecordFile(os.path.join(basedir, "files.xml")) sfiles = record.read() # restore those to their original locations for sfile in sfiles: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring file " + sfile.path) try: sfile.copy_to(self.fs_root, basedir) except: if snap.config.options.log_level_at_least('normal'): snap.callback.snapcallback.message( "Failed to restore file " + sfile.path)