def _get_store_backend(conf, destination=None, profile="default"): if not isinstance(conf, dict): conf = load_config(conf) conf = conf.get(profile) if not destination: destination = conf.get("default_destination", DEFAULT_DESTINATION) return STORAGE_BACKEND[destination](conf, profile), destination, conf
def match_filename(cls, filename, destination, **kwargs): conf = config if kwargs.get("config"): conf = load_config(kwargs.get("config")) profile = conf.get(kwargs.get("profile", "default")) s3_key = hashlib.sha512(profile.get("access_key") + profile.get("s3_bucket")).hexdigest() glacier_key = hashlib.sha512(profile.get("access_key") + profile.get("glacier_vault")).hexdigest() azure_container= hashlib.sha512(profile.get("access_key") + profile.get("azure_container")).hexdigest() try: fquery = "{0}*".format(path_leaf(filename)) a=Backups.select() a=[i for i in a ] query = Backups.select().where(Backups.filename % fquery | Backups.stored_filename % fquery, Backups.backend == destination, Backups.backend_hash << [s3_key, glacier_key,azure_container]) query = query.order_by(Backups.backup_date.desc()) return query.get() except Backups.DoesNotExist: return
def _get_store_backend(conf, destination=None, profile="default"): if not isinstance(conf, dict): conf = load_config(conf) if not isinstance(conf, dict) or len(conf) is 0: raise ValueError( "Failed to get configuration parameters. Maybe the config file wasn't found?" ) conf = conf.get(profile) setup_plugins(conf) if not destination: destination = conf.get("default_destination", DEFAULT_DESTINATION) return STORAGE_BACKEND[destination](conf, profile), destination, conf
def search(cls, query="", destination="", **kwargs): conf = config if kwargs.get("config"): conf = load_config(kwargs.get("config")) if not destination: destination = ["s3", "glacier"] if isinstance(destination, (str, unicode)): destination = [destination] query = "*{0}*".format(query) wheres = [] if kwargs.get("profile"): profile = conf.get(kwargs.get("profile")) s3_key = hashlib.sha512( profile.get("access_key") + profile.get("s3_bucket")).hexdigest() glacier_key = hashlib.sha512( profile.get("access_key") + profile.get("glacier_vault")).hexdigest() wheres.append(Backups.backend_hash << [s3_key, glacier_key]) wheres.append(Backups.filename % query | Backups.stored_filename % query) wheres.append(Backups.backend << destination) wheres.append(Backups.is_deleted == False) older_than = kwargs.get("older_than") if older_than: wheres.append(Backups.backup_date < older_than) backup_date = kwargs.get("backup_date") if backup_date: wheres.append(Backups.backup_date == backup_date) last_updated_gt = kwargs.get("last_updated_gt") if last_updated_gt: wheres.append(Backups.last_updated >= last_updated_gt) tags = kwargs.get("tags", []) if tags: if isinstance(tags, (str, unicode)): tags = tags.split() tags_query = ["Backups.tags % '*{0}*'".format(tag) for tag in tags] tags_query = eval("({0})".format(" and ".join(tags_query))) wheres.append(tags_query) return Backups.select().where(*wheres).order_by( Backups.last_updated.desc())
def search(cls, query="", destination="", **kwargs): conf = config if kwargs.get("config"): conf = load_config(kwargs.get("config")) if not destination: destination = ["s3", "glacier"] if isinstance(destination, (str, unicode)): destination = [destination] query = "*{0}*".format(path_leaf(query)) wheres = [] if kwargs.get("profile"): profile = conf.get(kwargs.get("profile")) s3_key = hashlib.sha512(profile.get("access_key") + profile.get("s3_bucket")).hexdigest() glacier_key = hashlib.sha512(profile.get("access_key") + profile.get("glacier_vault")).hexdigest() azure = hashlib.sha512(profile.get("access_key") + profile.get("azure_container")).hexdigest() wheres.append(Backups.backend_hash << [s3_key, glacier_key,azure]) wheres.append(Backups.filename % query | Backups.stored_filename % query) wheres.append(Backups.backend << destination) wheres.append(Backups.is_deleted == False) older_than = kwargs.get("older_than") if older_than: wheres.append(Backups.backup_date < older_than) backup_date = kwargs.get("backup_date") if backup_date: wheres.append(Backups.backup_date == backup_date) last_updated_gt = kwargs.get("last_updated_gt") if last_updated_gt: wheres.append(Backups.last_updated >= last_updated_gt) tags = kwargs.get("tags", []) if tags: if isinstance(tags, (str, unicode)): tags = tags.split() tags_query = ["Backups.tags % '*{0}*'".format(tag) for tag in tags] tags_query = eval("({0})".format(" and ".join(tags_query))) wheres.append(tags_query) return Backups.select().where(*wheres).order_by(Backups.last_updated.desc())
def match_filename(cls, filename, destination, **kwargs): conf = config if kwargs.get("config"): conf = load_config(kwargs.get("config")) profile = conf.get(kwargs.get("profile", "default")) s3_key = hashlib.sha512(profile.get("access_key") + profile.get("s3_bucket")).hexdigest() glacier_key = hashlib.sha512(profile.get("access_key") + profile.get("glacier_vault")).hexdigest() try: fquery = "{0}*".format(filename) query = Backups.select().where(Backups.filename % fquery | Backups.stored_filename % fquery, Backups.backend == destination, Backups.backend_hash << [s3_key, glacier_key]) query = query.order_by(Backups.backup_date.desc()) return query.get() except Backups.DoesNotExist: return
def periodic_backups(config=CONFIG_FILE, profile="default"): conf = load_config(config).get(profile) bakmanager_periodic_backups(conf)