borgmatic
Borgmatic installation
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install borgmatic -y
MULTIPLE BACKUP CONFIGURATIONS
You may find yourself wanting to create different backup policies for different applications on your system. For instance, you may want one backup configuration for your database data directory, and a different configuration for your user home directories.
The way to accomplish that is pretty simple: Create multiple separate configuration files and place each one in a /etc/borgmatic.d/ directory. For instance:
sudo mkdir /etc/borgmatic.d
sudo generate-borgmatic-config --destination /etc/borgmatic.d/app1.yaml
sudo generate-borgmatic-config --destination /etc/borgmatic.d/app2.yaml
VALIDATION
If you'd like to validate that your borgmatic configuration is valid, the following command is available for that:
sudo validate-borgmatic-config
mention -c for path
sudo validate-borgmatic-config -c borgmatic.yaml
By default, borgmatic extracts files into the current directory. To instead extract files to a particular destination directory, use the --destination flag:
borgmatic extract --archive host-2019-... --destination /tmp
When using the --destination flag, be careful not to overwrite your system's files with extracted files unless that is your intent.
AUTOPILOT
Running backups manually is good for validating your configuration, but I'm guessing that you want to run borgmatic automatically, say once a day. To do that, you can configure a separate job runner to invoke it periodically.
CRON
If you're using cron, download the sample cron file. Then, from the directory where you downloaded it:
sudo mv borgmatic /etc/cron.d/borgmatic
sudo chmod +x /etc/cron.d/borgmatic
If borgmatic is installed at a different location than /root/.local/bin/borgmatic, edit the cron file with the correct path. You can also modify the cron file if you'd like to run borgmatic more or less frequently.
SYSTEMD
If you're using systemd instead of cron to run jobs, you can still configure borgmatic to run automatically.
(If you installed borgmatic from Other ways to install, you may already have borgmatic systemd service and timer files. If so, you may be able to skip some of the steps below.)
First, download the sample systemd service file and the sample systemd timer file.
Then, from the directory where you downloaded them:
sudo mv borgmatic.service borgmatic.timer /etc/systemd/system/
sudo systemctl enable --now borgmatic.timer
Review the security settings in the service file and update them as needed. If ProtectSystem=strict is enabled and local repositories are used, then the repository path must be added to the ReadWritePaths list.
Feel free to modify the timer file based on how frequently you'd like borgmatic to run.
Enable timer
Configure borgmatic.service and borgmatic.timer
systemctl daemon-reload
sudo systemctl enable borgmatic.timer
sudo systemctl start borgmatic.timer
systemctl status borgmatic.timer
systemctl status borgmatic
sudo journalctl -u borgmatic
BACKUP PROGRESS
By default, borgmatic runs proceed silently except in the case of errors. But if you'd like to to get additional information about the progress of the backup as it proceeds, use the verbosity option:
borgmatic --verbosity 1
This lists the files that borgmatic is archiving, which are those that are new or changed since the last backup.
Or, for even more progress and debug spew:
borgmatic --verbosity 2
EXTRACT TO A PARTICULAR DESTINATION
By default, borgmatic extracts files into the current directory. To instead extract files to a particular destination directory, use the --destination flag:
borgmatic extract --archive Madhan-2022-03-30T09:53:31.793699 --destination /home/madhan/Projects/backup
When using the --destination flag, be careful not to overwrite your system's files with extracted files unless that is your intent.
Unzip tar files
tar -xvf filename
Create Read only user
CREATE ROLE read_access;
CREATE USER backup WITH PASSWORD 'backup';
GRANT read_access TO bip_read_user;
GRANT CONNECT ON DATABASE bip_dev TO read_access;
GRANT USAGE ON SCHEMA public TO "read_access";
GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO "read_access";
ALTER DEFAULT PRIVILEGES IN SCHEMA "public"
GRANT SELECT ON TABLES TO "read_access";
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO read_access;
Database Restore
chmod a+r /home/madhan/Projects/backup/qrcode
pg_restore -U postgres -Ft -C -d qrcode < /home/madhan/Projects/backup/qrcode