Restic Python Backup to S3 Compatible Storage

Home / Blog / Restic Python Backup to S3 Compatible Storage

Restic Python Backup to S3 Compatible Storage

Posted:  April 17, 2021

Restic Python Backup to S3 Compatible Storage

Forward

In my quest to get my servers fully automated, I realized I needed a reliable way to backup and restore my sites and databases.  Including a way to either browse the backups, or restore them to any other machine I have access to.

At first I thought… mmm…  duplicity seems nice, and while generally it is a viable solution, it did not quite have the OOOMPH I was looking for in my backups, so, in steps Restic, and Python.

This post is going to be mostly instructions on how to use my backup/restore binary’s and scripts, so if you need some more information about restic, please see here: https://restic.net/

Some of the backups are multi-threaded.

Description & Requirements

So, first things first, you are going to need a S3 compatible cloud object storage provider.  Something like Amazon’s S3 ( https://aws.amazon.com/s3/ ) will suffice, however, I would highly recommend giving Wasabi ( https://wasabi.com/ ) a chance (you won’t be disappointed)

Once you are signed up, you will need to gather some info to configure your backups.

  • Your S3 API Key
  • Your S3 API Secret
  • Your S3 API Endpoint (just the FQDN)
  • Your S3 Region
  • Your S3 Bucket

Got all that?   Great, don’t forget that I have set this up for my web servers, so you should probably gather up your MySQL admin info (either username and password, or the defaults file path), the starting path to your servers applications, as well, the name you wish to use for these backups and the “hash” you want to use to encrypt the backups.

Also note, this is created for Ubuntu based web servers primarily, so make sure your server is at least Ubuntu 18.04.  You also need to make sure your server has at least Python 3.6 installed.

Installing & Updating

At this point, you can go ahead and download the binary.  Yes, I did compile it to be a single binary, however, I did have to compile it separately for Ubuntu 18.04 and Ubuntu 20.04, so make sure you grab the right one for your distro.

Once you have it downloaded to your server, change the permissions on it to make it executable, rename it to kpbr, and move it to your /usr/bin/ directory.    This will make it that much easier to run it, especially when you need it for a cron job 🙂

Now, let’s get everything setup and ready to use.  Run the following command and pay attention.   kpbr -a setup  (NOTE: you’ll be doing this when I update the app too…   same download link, same command…).  It will get your server ready with the required modules and software to run.  (I’ll list that all out below…)

Once the setup is completed, it will automatically ask you to configure the app.  Just follow the prompts and answer the questions to finish… please do note, the hashes, keys & secrets are indeed secret, so you won’t be seeing them on the screen as you are typing or copying/pasting the information.

Backing Up and Restoring

Now that you are configured you can run your first backup.  Simply run the command: kpbr -a backup --what all to backup all web applications and databases on your server.

Now, if you need to restore an app or database, you have a few options.   You can do an automated restore, you can restore to a different location, or you can even mount the backups as a network drive and browse the files, you can also restore a backup from another machine if you want.  Just run the following command: kpbr -a restore and pay attention, you will be prompted to select what exactly it is you want to do.

Now for the nitty gritty of it:  I have the backups tested on both flavors of Ubuntu Server and Desktop, as well in the equivalent versions in WSL on Windows 10.   I also have the restores tested on the above as well.   I have tested the restores on Mac OS, however, have found there are too many differences in the Python versions and the modules for it to be able to support it (please I do not readily have access to a Mac), however, I have setup a bash script to allow you to be able to mount the backups as a network drive on a Mac.

The full readme, and command set is below, along with the repository of the source code.   If you do have any issues with this, please feel free to file an issue at the repo, just make sure you give me as much detail as possible.  I’ll at least need to know what OS you were using, along with what command you were running.

REQUIREMENTS

Operating System

    • Ubuntu 18.04+
    • Windows 10
      • Works and tested in WSL Ubuntu 18.04 & Ubuntu 20.04
      • Minor visual glitch with the select menus that go away if you go up and down once
      • UNTESTED in CYGWIN

Server Software & Binaries

    • NOTE: Do not run kpbr -a setup on Mac or Windows, instead please look up the proper documentation to install the proceeding packages for your system.
    • Python3.6+
      • Python dateutil, boto3, enquiries, mysqldb, invoke, & requests modules
      • for backing up & restore
    • restic
      • for backing up & restore
      • for restore/mount script
    • aws-cli
      • for restore selection
      • for restore/mount script
    • jq
      • for restore/mount script

INSTALL / UPDATE

For ubuntu, download the release binary associated to your flavor from here:

rename it to kpbr, make it executable, and move it to /usr/bin/

Once there, run sudo kpbr -a setup, it will install or update everything your server will need to run.

    • All in one command – Ubuntu 18.04: sudo wget https://kevinpirnie.com/kp/kpbr-18.04 -O kpbr && sudo chmod +x kpbr && sudo mv kpbr /usr/bin/ && sudo kpbr -a setup
    • All in one command – Ubuntu 20.04: sudo wget https://kevinpirnie.com/kp/kpbr-20.04 -O kpbr && sudo chmod +x kpbr && sudo mv kpbr /usr/bin/ && sudo kpbr -a setup

BACKUP MOUNT

Download and unzip the mount-scripts.zip from here: https://kevinpirnie.com/kp/mount-scripts.zip. You may need to make the 2 files executable.

Once expanded open .mb-source.sh and configure it. For the BACKUP_REPOS, it is a JSON string array. Follow the example to create more nodes.

USAGE – kpbr

 kpbr -a [setup|config|backup] [ARGS]

 Required Arguments Per Action:

 setup:
 NONE
 Will prompt you to configure or re-configure once the setup has been completed.

 config:
 NONE
 Will ask you questions to configure the app. Please pay attention carefully.

 backup:
 --what [all|db|database|acct|account|app|other]
 all: 
 NONE - also performs a full database backup
 db/database:
 --db or --database THE DATABASE NAME | ALL - REQUIRED 
 acct/account:
 --acct or --account THE ACCOUNT NAME - REQUIRED 
 app:
 --acct or --account THE ACCOUNT NAME - REQUIRED 
 --app THE APP NAME - REQUIRED 
 other:
 --paths COMMA-DELIMITED STRING OF FULL PATHS - REQUIRED 
 NOTE:
 --paths can also be passed for all|db/database|acct/account|app as well to add additional paths to backup

 restore:
 NONE: Everything will be prompted for you.
 PROMPTS:
 Backup Location:
 Local: this is the local server's backup. It will pull everything needed from the configured config file
 Remote: this is a remote servers backup. You will have to enter the S3 API Key, S3 API Secret, S3 Endpoint, S3 Bucket, S3 Region, backup name/server, and the backup hash. Make sure you have all this information handy, it is all required.
 Type of Backup:
 Application: Otherwise known as the web application, set of files to be restored.
 Addition Prompts:
 Account: The account to be restored
 Application: The application in the chosen account to be restored
 Snapshot: The specific backup point you would like to restore.
 Database: The database to be restored
 Addition Prompts:
 Database: The account to be restored
 Snapshot: The specific backup point you would like to restore.
 Restore Method:
 Automatic: This will overwrite the originals, so make sure you really want to do this.
 Manual: This will restore the files to the specified path. This includes the mysqldump if Database has been chosen as the type.
 Addition Prompts:
 Restore Path: The files will be restored to this path and be left alone for you to do with them as you see fit. The default is `/tmp/restore`
 Browse: This will mount the backup as a network drive, allowing you to browse the files as you see fit. The default mount point is `/tmp/backup-mount` however you can specify whatever path you see fit.
 Addition Prompts:
 Mount Point: The mount point that the backup will be mounted to, allowing you to browse the files as you see fit. The default mount point is `/tmp/backup-mount`

USAGE – MOUNT SCRIPTS

You can mount a backup as a networked drive.

Configure by opening .mb-source.sh and entering your AWS Key and Secret, the S3 Bucket, S3 Region, and S3 Endpoint (for aws this is s3.amazonaws.com).

Then add your server and server hash to the json nodes. name = the server or backup name, hash = the server hash

Once configured run the script mount-backup.sh then browse to /tmp/backup-mount/ on your machine. Inside it will contain the backups you selected. snapshots is the timestamped snapshots of the specified backup, with a symlink to the latest

REPO

https://gitlab.com/kp-development/python/kp-backup

Feel free to fork this, and if you run into any issues with it please fire up and issue at the repo so I can track it.

Thanks for looking and Happy Hosting!

Kevin Pirnie

20+ Years of PC and server maintenance & over 15+ years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.

Cookie Notice

This site utilizes cookies to improve your browsing experience, analyze the type of traffic we receive, and serve up proper content for you. If you wish to continue browsing, you must agree to allow us to set these cookies. If not, please visit another website.

Restic Python Backup to S3 Compatible Storage

Forward

In my quest to get my servers fully automated, I realized I needed a reliable way to backup and restore my sites and databases.  Including a way to either browse the backups, or restore them to any other machine I have access to.

At first I thought… mmm…  duplicity seems nice, and while generally it is a viable solution, it did not quite have the OOOMPH I was looking for in my backups, so, in steps Restic, and Python.

This post is going to be mostly instructions on how to use my backup/restore binary’s and scripts, so if you need some more information about restic, please see here: https://restic.net/

Some of the backups are multi-threaded.

Description & Requirements

So, first things first, you are going to need a S3 compatible cloud object storage provider.  Something like Amazon’s S3 ( https://aws.amazon.com/s3/ ) will suffice, however, I would highly recommend giving Wasabi ( https://wasabi.com/ ) a chance (you won’t be disappointed)

Once you are signed up, you will need to gather some info to configure your backups.

  • Your S3 API Key
  • Your S3 API Secret
  • Your S3 API Endpoint (just the FQDN)
  • Your S3 Region
  • Your S3 Bucket

Got all that?   Great, don’t forget that I have set this up for my web servers, so you should probably gather up your MySQL admin info (either username and password, or the defaults file path), the starting path to your servers applications, as well, the name you wish to use for these backups and the “hash” you want to use to encrypt the backups.

Also note, this is created for Ubuntu based web servers primarily, so make sure your server is at least Ubuntu 18.04.  You also need to make sure your server has at least Python 3.6 installed.

Installing & Updating

At this point, you can go ahead and download the binary.  Yes, I did compile it to be a single binary, however, I did have to compile it separately for Ubuntu 18.04 and Ubuntu 20.04, so make sure you grab the right one for your distro.

Once you have it downloaded to your server, change the permissions on it to make it executable, rename it to kpbr, and move it to your /usr/bin/ directory.    This will make it that much easier to run it, especially when you need it for a cron job 🙂

Now, let’s get everything setup and ready to use.  Run the following command and pay attention.   kpbr -a setup  (NOTE: you’ll be doing this when I update the app too…   same download link, same command…).  It will get your server ready with the required modules and software to run.  (I’ll list that all out below…)

Once the setup is completed, it will automatically ask you to configure the app.  Just follow the prompts and answer the questions to finish… please do note, the hashes, keys & secrets are indeed secret, so you won’t be seeing them on the screen as you are typing or copying/pasting the information.

Backing Up and Restoring

Now that you are configured you can run your first backup.  Simply run the command: kpbr -a backup --what all to backup all web applications and databases on your server.

Now, if you need to restore an app or database, you have a few options.   You can do an automated restore, you can restore to a different location, or you can even mount the backups as a network drive and browse the files, you can also restore a backup from another machine if you want.  Just run the following command: kpbr -a restore and pay attention, you will be prompted to select what exactly it is you want to do.

Now for the nitty gritty of it:  I have the backups tested on both flavors of Ubuntu Server and Desktop, as well in the equivalent versions in WSL on Windows 10.   I also have the restores tested on the above as well.   I have tested the restores on Mac OS, however, have found there are too many differences in the Python versions and the modules for it to be able to support it (please I do not readily have access to a Mac), however, I have setup a bash script to allow you to be able to mount the backups as a network drive on a Mac.

The full readme, and command set is below, along with the repository of the source code.   If you do have any issues with this, please feel free to file an issue at the repo, just make sure you give me as much detail as possible.  I’ll at least need to know what OS you were using, along with what command you were running.

REQUIREMENTS

Operating System

    • Ubuntu 18.04+
    • Windows 10
      • Works and tested in WSL Ubuntu 18.04 & Ubuntu 20.04
      • Minor visual glitch with the select menus that go away if you go up and down once
      • UNTESTED in CYGWIN

Server Software & Binaries

    • NOTE: Do not run kpbr -a setup on Mac or Windows, instead please look up the proper documentation to install the proceeding packages for your system.
    • Python3.6+
      • Python dateutil, boto3, enquiries, mysqldb, invoke, & requests modules
      • for backing up & restore
    • restic
      • for backing up & restore
      • for restore/mount script
    • aws-cli
      • for restore selection
      • for restore/mount script
    • jq
      • for restore/mount script

INSTALL / UPDATE

For ubuntu, download the release binary associated to your flavor from here:

rename it to kpbr, make it executable, and move it to /usr/bin/

Once there, run sudo kpbr -a setup, it will install or update everything your server will need to run.

    • All in one command – Ubuntu 18.04: sudo wget https://kevinpirnie.com/kp/kpbr-18.04 -O kpbr && sudo chmod +x kpbr && sudo mv kpbr /usr/bin/ && sudo kpbr -a setup
    • All in one command – Ubuntu 20.04: sudo wget https://kevinpirnie.com/kp/kpbr-20.04 -O kpbr && sudo chmod +x kpbr && sudo mv kpbr /usr/bin/ && sudo kpbr -a setup

BACKUP MOUNT

Download and unzip the mount-scripts.zip from here: https://kevinpirnie.com/kp/mount-scripts.zip. You may need to make the 2 files executable.

Once expanded open .mb-source.sh and configure it. For the BACKUP_REPOS, it is a JSON string array. Follow the example to create more nodes.

USAGE – kpbr

 kpbr -a [setup|config|backup] [ARGS]

 Required Arguments Per Action:

 setup:
 NONE
 Will prompt you to configure or re-configure once the setup has been completed.

 config:
 NONE
 Will ask you questions to configure the app. Please pay attention carefully.

 backup:
 --what [all|db|database|acct|account|app|other]
 all: 
 NONE - also performs a full database backup
 db/database:
 --db or --database THE DATABASE NAME | ALL - REQUIRED 
 acct/account:
 --acct or --account THE ACCOUNT NAME - REQUIRED 
 app:
 --acct or --account THE ACCOUNT NAME - REQUIRED 
 --app THE APP NAME - REQUIRED 
 other:
 --paths COMMA-DELIMITED STRING OF FULL PATHS - REQUIRED 
 NOTE:
 --paths can also be passed for all|db/database|acct/account|app as well to add additional paths to backup

 restore:
 NONE: Everything will be prompted for you.
 PROMPTS:
 Backup Location:
 Local: this is the local server's backup. It will pull everything needed from the configured config file
 Remote: this is a remote servers backup. You will have to enter the S3 API Key, S3 API Secret, S3 Endpoint, S3 Bucket, S3 Region, backup name/server, and the backup hash. Make sure you have all this information handy, it is all required.
 Type of Backup:
 Application: Otherwise known as the web application, set of files to be restored.
 Addition Prompts:
 Account: The account to be restored
 Application: The application in the chosen account to be restored
 Snapshot: The specific backup point you would like to restore.
 Database: The database to be restored
 Addition Prompts:
 Database: The account to be restored
 Snapshot: The specific backup point you would like to restore.
 Restore Method:
 Automatic: This will overwrite the originals, so make sure you really want to do this.
 Manual: This will restore the files to the specified path. This includes the mysqldump if Database has been chosen as the type.
 Addition Prompts:
 Restore Path: The files will be restored to this path and be left alone for you to do with them as you see fit. The default is `/tmp/restore`
 Browse: This will mount the backup as a network drive, allowing you to browse the files as you see fit. The default mount point is `/tmp/backup-mount` however you can specify whatever path you see fit.
 Addition Prompts:
 Mount Point: The mount point that the backup will be mounted to, allowing you to browse the files as you see fit. The default mount point is `/tmp/backup-mount`

USAGE – MOUNT SCRIPTS

You can mount a backup as a networked drive.

Configure by opening .mb-source.sh and entering your AWS Key and Secret, the S3 Bucket, S3 Region, and S3 Endpoint (for aws this is s3.amazonaws.com).

Then add your server and server hash to the json nodes. name = the server or backup name, hash = the server hash

Once configured run the script mount-backup.sh then browse to /tmp/backup-mount/ on your machine. Inside it will contain the backups you selected. snapshots is the timestamped snapshots of the specified backup, with a symlink to the latest

REPO

https://gitlab.com/kp-development/python/kp-backup

Feel free to fork this, and if you run into any issues with it please fire up and issue at the repo so I can track it.

Thanks for looking and Happy Hosting!

Our Privacy Policy

Last Updated: June 18th, 2025

Introduction

Western Mass Hosting (“we,” “our,” or “us”) respects the privacy of all individuals and organizations that interact with our services. This Privacy Policy establishes our practices regarding the collection, use, disclosure, and protection of personal information for visitors to our website and clients utilizing our managed hosting and WordPress services. By accessing our website or engaging our services, you acknowledge that you have read and understood this policy in its entirety.

Scope and Applicability

This Privacy Policy governs our handling of information collected through our corporate website and in the course of providing managed hosting, WordPress maintenance, and development services. In accordance with global privacy regulations, we serve as a Data Controller for information related to our business operations and client relationships. When processing data on behalf of our clients through hosted services, we act as a Data Processor under applicable data protection laws.

Information We Collect

We collect various categories of information necessary to provide and improve our services. This includes personal contact and payment details provided during account registration, technical information such as IP addresses and device characteristics for security purposes, and records of communications through support channels. For clients utilizing our hosting services, we may process end-user data stored within client websites, though we do not control or monitor the collection practices of such data.

Purpose and Legal Basis for Processing

We process personal information only when we have proper justification under applicable laws. The primary legal bases for our processing activities include the necessity to fulfill contractual obligations to our clients, our legitimate business interests in maintaining and improving our services, and in limited cases, explicit consent for specific marketing communications. We maintain detailed records of processing activities to demonstrate compliance with legal requirements.

Use of Collected Information

The information we collect serves multiple business purposes. Primarily, we use this data to deliver and maintain reliable hosting services, including server provisioning, performance monitoring, and technical support. We also utilize information for business operations such as billing, customer relationship management, and service improvement initiatives. Security represents another critical use case, where we analyze data to detect and prevent fraudulent activity or unauthorized access to our systems.

Data Sharing and Third-Party Disclosures

We engage with carefully selected third-party service providers to support our operations, including cloud infrastructure providers, payment processors, and customer support platforms. These relationships are governed by strict contractual agreements that mandate appropriate data protection measures. We may disclose information when legally required to comply with court orders, government requests, or to protect our legal rights and the security of our services.

International Data Transfers

As a global service provider, we may transfer and process data in various locations worldwide. When transferring personal data originating from the European Economic Area or other regulated jurisdictions, we implement appropriate safeguards such as Standard Contractual Clauses and rely on adequacy decisions where applicable. Our subprocessors, including AWS Lightsail, maintain robust compliance certifications to ensure the protection of transferred data.

Data Retention Practices

We retain personal information only for as long as necessary to fulfill the purposes outlined in this policy. Client account information is typically maintained for five years following service termination to comply with legal and financial reporting obligations. Backup data associated with hosting services is automatically purged after thirty days, as specified in our Terms of Service. For data processed on behalf of clients, retention periods are determined by the respective client’s policies and instructions.

Security Measures

We implement comprehensive technical and organizational security measures to protect personal information against unauthorized access, alteration, or destruction. Our security program includes network encryption protocols, regular vulnerability assessments, strict access controls, and employee training on data protection best practices. We maintain incident response procedures to address potential security breaches and will notify affected parties where required by law.

Individual Rights

Individuals whose personal data we process may exercise certain rights under applicable privacy laws. These rights may include requesting access to their information, seeking correction of inaccurate data, requesting deletion under specific circumstances, and objecting to particular processing activities. We have established procedures to handle such requests in accordance with legal requirements, typically responding within thirty days of receipt. Requests should be submitted to our designated Data Protection Officer through the contact information provided in this policy.

Cookies and Tracking Technologies

Our website employs various technologies to enhance user experience and analyze site performance. Essential cookies are used for basic functionality and security purposes, while analytics cookies help us understand how visitors interact with our site. Marketing cookies are only deployed with explicit user consent. Visitors can manage cookie preferences through their browser settings or our cookie consent tool.

Policy Updates and Notifications

We periodically review and update this Privacy Policy to reflect changes in our practices or legal obligations. Material changes will be communicated to affected clients through email notifications at least thirty days prior to implementation. Continued use of our services following such notifications constitutes acceptance of the revised policy.

Contact Information

For questions or concerns regarding this Privacy Policy or our privacy practices, please contact our Data Protection Officer at info@westernmasshosting.com or by mail at:

Western Mass Hosting
22 Orlando. St.,
Feeding Hills, MA 01030.

We take all privacy-related inquiries seriously and will respond promptly to legitimate requests. For clients with specific data processing agreements, please reference your contract for any additional terms that may apply to our handling of your data.