def lof_record(self, folder, name, type, mod_time=None, size=None): # Save the entry in the LOF log.trace("lof_record", folder, name) if folder != self.lof_folder: self.lof.write("\n%s\n" % utils.escape(folder)) self.lof_folder = folder self.lof.write("%s,%s" % (type, utils.escape(name))) if mod_time: self.lof.write(',%s,%d' % (mod_time, size)) self.lof.write("\n")
def do_backup_folder(self, folder, name): log.trace("do_backup_folder", folder, name) path = os.path.join(folder, name) if self.dry_run: print("D - %s" % utils.escape(path)) sys.stdout.flush() return # We dont need to add it to the try: self.tarfile.add(name=path, recursive=False) mod_time = self.get_file_time_str(path) size = 0 type = 'D' self.db.fs_saved(path, mod_time, size, type) self.nfolders += 1 # Save the entry in the LOF self.lof_record(folder, name, "D", mod_time, size) except Exception as e: log.warn("Exception backing up folder %s: %s" % (path, str(e))) # If the exception is in the store - we crash and burn # as we cannot save if self.store_thread.error: raise self.store_thread.error # Otherwise log it and keep going... msg = "Unable to backup %s: %s" % (path, str(e)) self.db.save_message(msg) log.warn(msg)
def copy_file(self, path, name=None): log.debug("CopyFile: ", path, name) if not name: name = os.path.basename(path) if self.dry_run: print(utils.escape(name)) sys.stdout.flush() else: if self.backup.encrypt: if name: name = name + ".enc" # Otherwise left as None enc_path = path + ".enc" cryptor.encrypt_file(self.config.data_passphrase, path, enc_path) self.store.send(enc_path, os.path.join(self.backup_folder, name)) os.remove(enc_path) else: self.store.send(path, os.path.join(self.backup_folder, name))
def create(self): # Get all params from the html form data = self.get_data("title", "blob", "author", "genre", "description", "author_description") fields = [data["title"], data["author"], data["genre"], data["description"], data["author_description"]] invalid_form = BookModel.invalid_form(fields, data["blob"]) if not invalid_form: for f in fields: f = utils.escape(f) # HTML-Safe return data else: self.redirect('/books/new')
def do_backup_deleted(self, folder, name): path = os.path.join(folder, name) if self.dry_run: print("X - %s" % utils.escape(path)) sys.stdout.flush() return try: log.debug("FILE/FOLDER DELETED:", name) self.db.fs_deleted(path) # We keep track of deletions self.lof_record(folder, name, "X") except Exception as e: # If the exception is in the store - we crash and burn # as we cannot save if self.store_thread.error: raise self.store_thread.error # Otherwise log it and keep going... msg = "Unable to backup %s: %s" % (path, str(e)) self.db.save_message(msg) log.warn(msg)
def do_backup_file(self, folder, name): log.trace("do_backup_file", folder, name) path = os.path.join(folder, name) if self.dry_run: print("F - %s" % utils.escape(path)) sys.stdout.flush() return # Add it to the tar try: # What's the encoding on the file? upath = utils.path_to_unicode(path) uname = utils.path_to_unicode(name) ufolder = utils.path_to_unicode(folder) # Due to issues with encoding... I'll open the file myself and pass to tar with open(path, "rb") as f: info = self.tarfile.gettarinfo(arcname=upath, fileobj=f) self.tarfile.addfile(info, f) #self.tarfile.addfile(name=path, recursive=False) mod_time = self.get_file_time_str(path) size = os.path.getsize(path) type = 'F' self.db.fs_saved(upath, mod_time, size, type) self.nfiles += 1 # Save the entry in the LOF self.lof_record(ufolder, uname, "F", mod_time, size) except Exception as e: # If the exception is in the store - we crash and burn # as we cannot save if self.store_thread.error: raise self.store_thread.error # Otherwise log it and keep going... msg = "Unable to backup %s: %s" % (path, str(e)) self.db.save_message(msg) log.warn(msg)