How to use the command 'borg' (with examples)

How to use the command 'borg' (with examples)

Borg is a deduplicating backup tool that creates local or remote backups, which can be mounted as filesystems. It is a reliable and efficient solution for managing backups and ensuring data integrity.

Use case 1: Initialize a (local) repository

Code:

borg init path/to/repo_directory

Motivation: You want to start using Borg for backups and need to create a repository to store the backup data.

Explanation:

  • borg init: Initializes a Borg repository.
  • path/to/repo_directory: Specifies the directory where the repository will be created.

Example output:

Initialized empty repository at path/to/repo_directory.

Use case 2: Backup a directory into the repository

Code:

borg create --progress path/to/repo_directory::Monday path/to/source_directory

Motivation: You want to create a backup of a directory and store it in the repository with a specific name (e.g., “Monday”).

Explanation:

  • borg create: Creates a new archive.
  • --progress: Displays progress information during the backup process.
  • path/to/repo_directory::Monday: Specifies the repository and archive name.
  • path/to/source_directory: Specifies the directory to be backed up.

Example output:

Archive name: Monday
Created archive path/to/repo_directory::Monday

Use case 3: List all archives in a repository

Code:

borg list path/to/repo_directory

Motivation: You want to see a list of all archives stored in the repository.

Explanation:

  • borg list: Lists all archives in a repository.
  • path/to/repo_directory: Specifies the repository to be listed.

Example output:

Monday
Tuesday
Wednesday

Use case 4: Extract a specific directory from an archive

Code:

borg extract user@host:path/to/repo_directory::Monday path/to/target_directory --exclude '*.ext'

Motivation: You need to extract a specific directory from a remote repository’s archive, excluding files with a specific file extension.

Explanation:

  • borg extract: Extracts files from an archive.
  • user@host:path/to/repo_directory::Monday: Specifies the remote repository, archive name, and directory to be extracted.
  • path/to/target_directory: Specifies the directory where the extracted files will be stored.
  • --exclude '*.ext': Excludes files with the “*.ext” file extension from the extraction.

Example output:

Extracting files from archive: Monday
Extracted directory path/to/source_directory to path/to/target_directory

Use case 5: Prune a repository

Code:

borg prune --keep-within 7d --list path/to/repo_directory

Motivation: You want to remove old archives from a repository while maintaining a specific retention period (e.g., deleting archives older than 7 days).

Explanation:

  • borg prune: Prunes (deletes) archives from a repository.
  • --keep-within 7d: Specifies the retention period, keeping only archives within the specified time frame (7 days in this example).
  • --list: Displays a list of archives that will be pruned.
  • path/to/repo_directory: Specifies the repository to be pruned.

Example output:

The following archives will be deleted:
- Wednesday
- Thursday
- Friday
Deleted 3 archives from path/to/repo_directory

Use case 6: Mount a repository as a FUSE filesystem

Code:

borg mount path/to/repo_directory::Monday path/to/mountpoint

Motivation: You want to access the content of an archive in the repository as if it were a filesystem to browse and retrieve specific files.

Explanation:

  • borg mount: Mounts a repository as a FUSE filesystem.
  • path/to/repo_directory::Monday: Specifies the repository and archive name to be mounted.
  • path/to/mountpoint: Specifies the directory where the mounted filesystem will be accessible.

Example output:

Mounted archive Monday as FUSE filesystem at path/to/mountpoint

Use case 7: Display help on creating archives

Code:

borg create --help

Motivation: You need information on the available options and usage of the borg create command.

Explanation:

  • borg create: The target command for which help information is requested.
  • --help: Displays detailed help documentation for the specific command.

Example output:

Help documentation for the "borg create" command.
(Displays usage options, available arguments, and examples)

Conclusion:

In this article, we explored various use cases of the borg command, a deduplicating backup tool. We learned how to initialize a repository, create backups, list archives, extract specific directories, prune old archives, mount repositories as filesystems, and access help documentation. Borg provides a versatile and efficient solution for managing backups, ensuring data integrity, and simplifying data recovery.

Related Posts

How to use the command pnmremap (with examples)

How to use the command pnmremap (with examples)

The command pnmremap is used to replace the colors in a PNM (Portable Any Map) image.

Read More
A Comprehensive Guide to Using the `ocspd` Command (with examples)

A Comprehensive Guide to Using the `ocspd` Command (with examples)

Introduction In this article, we will explore the various use cases of the ocspd command.

Read More
ld Command Examples (with examples)

ld Command Examples (with examples)

Link a specific object file with no dependencies into an executable ld path/to/file.

Read More