REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2io.backup#

Module Contents#

Functions#

backup_data_directory([timestamp, dir_backup])

Backup the Brightway2 data directory to a .tar.gz (compressed tar archive) in a specified directory, or in the user's home directory by default.

backup_project_directory(project[, timestamp, dir_backup])

Backup project data directory to a .tar.gz (compressed tar archive) in the user's home directory, or a directory specified by dir_backup.

restore_project_directory(fp[, project_name, ...])

Restore a backed up project data directory from a .tar.gz (compressed tar archive) specified by fp. Choose a custom name, or use the name of the project in the archive. If the project already exists, you must set overwrite_existing to True.

bw2io.backup.backup_data_directory(timestamp: bool | None = True, dir_backup: str | pathlib.Path | None = None)[source]#

Backup the Brightway2 data directory to a .tar.gz (compressed tar archive) in a specified directory, or in the user’s home directory by default.

The file name is of the form “brightway2-data-backup.{timestamp}.tar.gz”, unless timestamp is False, in which case the file name is “brightway2-data-backup.tar.gz”.

Parameters#

timestampbool, optional

If True, append a timestamp to the backup file name.

dir_backupstr, Path, optional

Directory to backup. If None, use the user’s home directory.

Raises#

FileNotFoundError

If the backup directory does not exist.

PermissionError

If the backup directory is not writable.

Examples#

>>> import bw2io
>>> bw2io.bw2setup()
>>> bw2io.backup.backup_data_directory()
Creating backup archive - this could take a few minutes...
bw2io.backup.backup_project_directory(project: str, timestamp: bool | None = True, dir_backup: str | pathlib.Path | None = None)[source]#

Backup project data directory to a .tar.gz (compressed tar archive) in the user’s home directory, or a directory specified by dir_backup.

File name is of the form brightway2-project-{project}-backup{timestamp}.tar.gz, unless timestamp is False, in which case the file name is brightway2-project-{project}-backup.tar.gz.

Parameters#

projectstr

Name of the project to backup.

timestampbool, optional

If True, append a timestamp to the backup file name.

dir_backupstr, Path, optional

Directory to backup. If None, use the default (home)).

Returns#

project_namestr

Name of the project that was backed up.

Raises#

ValueError

If the project does not exist.

FileNotFoundError

If the backup directory does not exist.

PermissionError

If the backup directory is not writable.

See Also#

bw2io.backup.restore_project_directory: To restore a project directory from a backup.

bw2io.backup.restore_project_directory(fp: str | pathlib.Path, project_name: str | None = None, overwrite_existing: bool | None = False)[source]#

Restore a backed up project data directory from a .tar.gz (compressed tar archive) specified by fp. Choose a custom name, or use the name of the project in the archive. If the project already exists, you must set overwrite_existing to True.

Parameters#

fpstr, Path

File path of the project to restore.

project_namestr, optional

Name of new project to create

overwrite_existing : bool, optional

Returns#

project_namestr, Path

Name of the project that was restored.

Raises#

FileNotFoundError

If the file path does not exist.

ValueError

If the project name cannot be found in the archive. If the project exists and overwrite_existing is False.

See Also#

bw2io.backup.backup_project_directory: To backup a project directory.