To set up BorgBackup to back up the contents of /media/veracrypt1/myfiles and store the backup in /media/veracrypt1/backup, you can follow these steps:
If you haven’t installed BorgBackup yet, you can do so using the following command (for a system like Ubuntu/Debian):
sudo apt update
sudo apt install borgbackupFor other systems, you can follow the installation instructions from the BorgBackup documentation.
A repository is where Borg stores your backups. You need to initialize a repository in /media/veracrypt1/backup.
Run the following command to initialize the Borg repository:
borg init --encryption=repokey /media/veracrypt1/backup--encryption=repokeyenables encryption, which is recommended for security. Borg will generate a key for encrypting the backups.
Now you can create your first backup of the /media/veracrypt1/myfiles directory. To do this, use the following borg create command:
borg create /media/veracrypt1/backup::backup-$(date +%Y-%m-%d) /media/veracrypt1/myfilesHere’s what each part does:
/media/veracrypt1/backup::backup-$(date +%Y-%m-%d): This specifies the location where the backup will be stored, with the name of the backup set to the current date (backup-YYYY-MM-DD)./media/veracrypt1/myfiles: This is the directory you want to back up.
If you want to exclude some files or directories from the backup, you can create an exclude file that lists paths to exclude. For example:
echo "/media/veracrypt1/myfiles/ignore_this_folder" > exclude-list.txtTo use the exclude-list.txt when creating the backup, you can modify the command:
borg create --exclude-from exclude-list.txt /media/veracrypt1/backup::backup-$(date +%Y-%m-%d) /media/veracrypt1/myfilesOnce you have the initial backup (full backup), subsequent backups will be incremental. To create the next incremental backup, simply run the same borg create command again:
borg create /media/veracrypt1/backup::backup-$(date +%Y-%m-%d) /media/veracrypt1/myfilesThis will only store the changes made since the last backup.
To restore files from a backup, you can use the borg extract command. For example, to restore the files from backup-2025-01-15:
borg extract /media/veracrypt1/backup::backup-2025-01-15To automate your backups, you can schedule the backup process using cron (or systemd timers if preferred). For example, to run backups every day at 3 AM:
-
Open the crontab file with:
crontab -e
-
Add a line to schedule the backup:
0 3 * * * /usr/bin/borg create /media/veracrypt1/backup::backup-$(date +\%Y-\%m-\%d) /media/veracrypt1/myfiles
This will create a backup every day at 3 AM.
- Initialize Borg repository with encryption.
- Create a full backup of
/media/veracrypt1/myfilesusingborg create. - For subsequent backups, just run
borg createagain, and Borg will only back up the changes. - Optionally, automate backups using cron.
By following these steps, you can set up and manage regular encrypted backups of /media/veracrypt1/myfiles to /media/veracrypt1/backup.