Exemplo n.º 1
0
def delete_backup(file_name: str):
    """ Removes a database backup from the file system """

    try:
        BACKUP_DIR.joinpath(file_name).unlink()
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Delete Backup. See Log File"),
        )

    return SnackResponse.error(f"{file_name} Deleted")
Exemplo n.º 2
0
    def finish_export(self):
        zip_path = BACKUP_DIR.joinpath(f"{self.main_dir.name}")
        shutil.make_archive(zip_path, "zip", self.main_dir)

        shutil.rmtree(TEMP_DIR)

        return str(zip_path.absolute()) + ".zip"
Exemplo n.º 3
0
async def upload_nextcloud_zipfile(file_name: str):
    """ Upload a .zip File to later be imported into Mealie """
    file = BACKUP_DIR.joinpath(file_name)

    if file.is_file:
        return FileResponse(file,
                            media_type="application/octet-stream",
                            filename=file_name)
    else:
        return SnackResponse.error("No File Found")
Exemplo n.º 4
0
def auto_backup_job():
    for backup in BACKUP_DIR.glob("Auto*.zip"):
        backup.unlink()

    templates = []
    for template in TEMPLATE_DIR.iterdir():
        templates.append(template)

    backup_all(tag="Auto", templates=templates)
    logger.info("Auto Backup Called")
Exemplo n.º 5
0
def upload_backup_zipfile(archive: UploadFile = File(...)):
    """ Upload a .zip File to later be imported into Mealie """
    dest = BACKUP_DIR.joinpath(archive.filename)

    with dest.open("wb") as buffer:
        shutil.copyfileobj(archive.file, buffer)

    if dest.is_file:
        return SnackResponse.success("Backup uploaded")
    else:
        return SnackResponse.error("Failure uploading file")
Exemplo n.º 6
0
def available_imports():
    """Returns a list of avaiable .zip files for import into Mealie."""
    imports = []
    templates = []
    for archive in BACKUP_DIR.glob("*.zip"):
        backup = LocalBackup(name=archive.name, date=archive.stat().st_ctime)
        imports.append(backup)

    for template in TEMPLATE_DIR.glob("*.*"):
        templates.append(template.name)

    imports.sort(key=operator.attrgetter("date"), reverse=True)

    return Imports(imports=imports, templates=templates)
Exemplo n.º 7
0
    def __init__(
        self,
        session: Session,
        zip_archive: str,
        import_recipes: bool = True,
        import_settings: bool = True,
        import_themes: bool = True,
        force_import: bool = False,
        rebase: bool = False,
    ) -> None:
        """Import a database.zip file exported from mealie.

        Args:
            zip_archive (str): The filename contained in the backups directory
            import_recipes (bool, optional): Import Recipes?. Defaults to True.
            import_settings (bool, optional): Determines if settings are imported. Defaults to True.
            import_themes (bool, optional): Determines if themes are imported. Defaults to True.
            force_import (bool, optional): Force import will update all existing recipes. If False existing recipes are skipped. Defaults to False.
            rebase (bool, optional): Rebase will first clear the database and then import Recipes. Defaults to False.

        Raises:
            Exception: If the zip file does not exists an exception raise.
        """
        self.session = session
        self.archive = BACKUP_DIR.joinpath(zip_archive)
        self.imp_recipes = import_recipes
        self.imp_settings = import_settings
        self.imp_themes = import_themes
        self.force_imports = force_import
        self.force_rebase = rebase

        if self.archive.is_file():
            self.import_dir = TEMP_DIR.joinpath("active_import")
            self.import_dir.mkdir(parents=True, exist_ok=True)

            with zipfile.ZipFile(self.archive, "r") as zip_ref:
                zip_ref.extractall(self.import_dir)
            pass
        else:
            raise Exception("Import file does not exist")