Skip to content

Do-It-Yourself Backups

In this article

Built-in Invapi Tools

The following tools are available for virtual servers in the Invapi control panel:

  • Backups — copies of the VPS disk, created on a schedule or manually. As part of beta testing, the feature is available only for VPS in the Basic group (pico, nano, mini, and medium) in the NL (Netherlands) location; the total storage limit is 50 GB. A new server cannot be created from a downloaded backup via Invapi;
  • Snapshots — a copy of the VPS disk state. A snapshot is stored on the same node as the server, and only one snapshot can be stored at a time.

These tools are convenient for quick rollbacks, but they do not replace full-fledged backups: they are not available for dedicated servers, and a snapshot resides on the same hardware as the server itself. We therefore recommend additionally backing up important data with your own tools.

The 3-2-1 Rule

Follow the 3-2-1 rule:

  • 3 copies of your data — the working data and two backups;
  • 2 different types of media or storage;
  • 1 copy in another place (another server, another location, object storage).

In addition:

  • keep several backup versions (daily, weekly, monthly) so that you can recover from unnoticed corruption or ransomware;
  • encrypt backups if they are stored with a third party;
  • test restores regularly.

Tip

To store large volumes of backups, you can use a Storage server or S3 Object Storage.

Restic and HOSTKEY S3 Storage

Restic creates encrypted incremental backups with deduplication and works with S3-compatible storage.

  1. Create an S3 storage and a bucket in Invapi and obtain the access keys — see S3 Object Storage HOSTKEY.
  2. Install restic:

    # Debian/Ubuntu
    apt install restic
    # AlmaLinux/Rocky Linux (from the EPEL repository)
    dnf install epel-release && dnf install restic
    
  3. Create the file /root/.restic.env with the access parameters and restrict its permissions (chmod 600):

    export AWS_ACCESS_KEY_ID="your_access_key"
    export AWS_SECRET_ACCESS_KEY="your_secret_key"
    export RESTIC_REPOSITORY="s3:https://s3-nl.hostkey.com/bucket-name/server1"
    export RESTIC_PASSWORD="strong_encryption_password"
    

    Attention

    Store RESTIC_PASSWORD in a safe place outside the server. Without it, data cannot be restored from the repository.

  4. Initialize the repository and create the first backup:

    source /root/.restic.env
    restic init
    restic backup /etc /var/www /root/db_dumps --exclude-caches
    
  5. Configure version retention — for example, 7 daily, 4 weekly, and 6 monthly backups:

    restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
    

Back up databases with a dump rather than copying the files of a running DBMS — see Creating a Database Backup and Restoration.

BorgBackup

BorgBackup stores backups in a repository on another server accessible via SSH, for example a Storage server. The borgbackup package must be installed on both servers.

export BORG_REPO="ssh://backup@STORAGE_IP/home/backup/server1"
export BORG_PASSPHRASE="strong_password"

borg init --encryption=repokey
borg create --stats --compression zstd ::'{hostname}-{now:%Y-%m-%d}' /etc /var/www
borg prune --keep-daily 7 --keep-weekly 4 --keep-monthly 6
borg compact

Note

In repokey mode, the encryption key is stored in the repository and protected by the passphrase. Export it with borg key export and store it separately.

Rsync and cron

The simplest option is a daily synchronization of directories to another server. Add a job with crontab -e:

30 3 * * * rsync -aHAX --delete /var/www/ backup@STORAGE_IP:/backup/server1/www/ >> /var/log/backup.log 2>&1

Attention

rsync with the --delete option keeps only the latest state: deleted or corrupted files will disappear from the copy the next day as well. Use restic or borg to keep multiple versions.

Scheduling with a systemd Timer

Instead of cron, you can use a systemd timer: it keeps a log and runs missed jobs after the server is powered on.

  1. Create the script /usr/local/bin/backup.sh and make it executable (chmod +x):

    #!/bin/bash
    set -e
    source /root/.restic.env
    mysqldump --single-transaction --all-databases > /root/db_dumps/all.sql
    restic backup /etc /var/www /root/db_dumps
    restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
    
  2. Create the service /etc/systemd/system/backup.service:

    [Unit]
    Description=Restic backup
    
    [Service]
    Type=oneshot
    ExecStart=/usr/local/bin/backup.sh
    
  3. Create the timer /etc/systemd/system/backup.timer:

    [Unit]
    Description=Daily restic backup
    
    [Timer]
    OnCalendar=*-*-* 03:30:00
    Persistent=true
    
    [Install]
    WantedBy=timers.target
    
  4. Enable the timer and check the schedule:

    systemctl daemon-reload
    systemctl enable --now backup.timer
    systemctl list-timers backup.timer
    journalctl -u backup.service
    

Testing Restores

A backup can be considered working only after a successful restore. At least once a month, run:

restic snapshots
restic check
restic restore latest --target /tmp/restore-test --include /etc/nginx

For borg:

borg list
borg extract --dry-run ::archive-name

Restore the database from a dump on a test server or into a separate database and make sure your application works with it.

Windows Backups

On Windows Server, use the Windows Server Backup feature. Install it in PowerShell as Administrator:

Install-WindowsFeature Windows-Server-Backup

Create a backup of the system and data on a network share:

wbadmin start backup -backupTarget:\\STORAGE_IP\backup -allCritical -include:C:,D: -quiet

To run backups regularly, configure a schedule in the Windows Server Backup snap-in (wbadmin.msc) or create a task in Task Scheduler. To list the existing backups, run:

wbadmin get versions -backupTarget:\\STORAGE_IP\backup

Note

When writing to a network folder, Windows Server Backup keeps only the latest backup — each new one overwrites the previous one. To keep multiple versions, use a dedicated disk or third-party tools such as restic for Windows.

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×