def restore(self): """ Remove the current directory's contents and replace it with .backup/contents """ if not vc.is_init(self.backup_path, [self.contents_path], self.index_path, self.identity_string): print(self.not_exist_msg) return False del_files = os.listdir() del_files.remove(self.backup_path) vc.rm(del_files,".") files = os.listdir(self.contents_path) vc.cp(zip(files,files),self.contents_path,".") return True
def restore(self,revision=-1): if not vc.is_init(self.backup_path, [self.contents_path], self.index_path, self.identity_string): print(self.not_exist_msg) return False # If -1, find the last revision if revision==-1: revision==len(open(self.index_path,"r").read().split('\n')) # pull up the catalogue of files and directory structure files catalogue = os.path.join(self.revisions_path,str(revision)) structure = os.path.join(self.revisions_path,str(revision)+"d") if not (os.path.exists(catalogue) and os.path.exists(structure)): print(self.no_existing_backup) return False # STEVE: Do we want to remove all files in the current dir? del_files = os.listdir(".") del_files.remove(self.backup_path) vc.rm(del_files, ".") # rebuild structure from the file dirfile = open(structure,'r') dirs = dirfile.read().split('\n') dirfile.close() for d in dirs: os.mkdir(d) # generate pairs of files and hashes (actually file names in files/) catfile = open(catalogue,'r') files = [(p[1],p[0]) for p in [line.split(' ') for line in catfile.read().split('\n')]] catfile.close() # simply copy them to the current directory vc.cp(files,self.contents_path,".") return True
def restore(self,backup_no=-1): """ Remove the current directory's contents and replace it with backup number selected """ if not vc.is_init(self.backup_path, [self.contents_path], self.index_path, self.identity_string): print(self.not_exist_msg) return False if backup_no==-1: backup_no = len(self.get_backups()) backup_file_path = os.path.join(self.contents_path, str(backup_no)) if backup_no == 0 or not os.path.exists(backup_file_path): print(self.no_existing_backup) return False del_files = os.listdir(".") del_files.remove(self.backup_path) vc.rm(del_files, ".") files = os.listdir(backup_file_path) return vc.cp(zip(files,files),backup_file_path,".")