Automated Data Backup Solution from VPS to Home NAS Using Kopia with High-Security SFTP Connection
An automated data backup solution from VPS to home NAS using Kopia with high-security SFTP connection protects critical data from hardware failure, user errors, or cyberattacks....
Image credit: analogicus · Pixabay Content License
Automated data backup from a Virtual Private Server (VPS) to a home Network Attached Storage (NAS) device using Kopia with a high-security SFTP connection protects critical data from hardware failure, user errors, or cyberattacks. Kopia provides end-to-end encryption, data compression, and automatic scheduled backups, while SFTP ensures secure data transfer over public networks. This guide covers installing Kopia, configuring secure SFTP access, and setting up automated backup schedules on a VPS environment.
Introduction to Automated Data Backup Solution
Data backup is a critical component of any organization’s data security and recovery strategy. With virtual private servers (VPS), data loss can occur due to software errors, ransomware attacks, or hardware failures. An automated backup solution from VPS to a home NAS reduces this risk by copying important data to a secure local storage device, typically a NAS at home or office. Using Kopia with a high-security SFTP connection ensures that data is encrypted before transmission and securely stored on the NAS.
Kopia is an open-source, lightweight, and efficient backup tool that supports end-to-end encryption using user-managed private keys. This means even if data is intercepted during transmission or storage, attackers cannot decrypt it. Kopia also offers data compression, deduplication, and automatic scheduled backups, optimizing storage space and reducing system load. The Secure File Transfer Protocol (SFTP), based on SSH, provides an encrypted communication channel between the VPS and NAS, preventing data interception during backup.
Setting Up Kopia on VPS
To deploy the solution, the first step is to install Kopia on your VPS. You can use the official package or build from source. Below are the installation steps using the official package on Linux (e.g., Ubuntu/Debian):
sudo apt update
sudo apt install -y curl
curl -s https://packagecloud.io/install/repositories/kopia/kopia/script.deb.sh | sudo bash
sudo apt install -y kopia
After installation, initialize the Kopia repository. This repository will store all backup data and necessary recovery information. You must specify the storage location, such as a directory on the NAS via SFTP connection.
To initialize the repository, provide the repository path and encryption password. Here is an example with SFTP connection:
kopia repository create sftp://user@nas-ip-address/path/to/repository --password
Replace `user` with the NAS username, `nas-ip-address` with the NAS IP address, and `path/to/repository` with the target directory on the NAS. Kopia will prompt you to enter the encryption password, which is the most important key to protect your backup data. Store this password securely.
Configuring Secure SFTP Connection and Backup Schedule
A secure SFTP connection requires SSH key authentication. Use SSH keys instead of passwords to enhance security. On the VPS, generate an SSH key pair if you don’t have one:
ssh-keygen -t ed25519 -C "backup@vps"
Then copy the public key to the NAS. You can do this using the `ssh-copy-id` command or manually paste it into the `~/.ssh/authorized_keys` file on the NAS. This allows the VPS to connect to the NAS without entering a password each time.
After setting up the connection, create an automated backup command. Kopia supports backup commands with the `backup` and `schedule` options. For example, to back up the `/home` directory daily at 2 AM:
kopia snapshot create /home --schedule="0 2 * * *"
To manage backup schedules, use the commands `kopia schedule list` and `kopia schedule create`. Kopia will automatically perform backups according to the defined schedule. You can also configure options such as encryption, compression, and bandwidth limits to optimize performance.
Testing and Troubleshooting
To ensure the solution works correctly, perform the following checks:
- Test SFTP Connection: Use the command `ssh user@nas-ip-address` to verify that the VPS can connect to the NAS via SSH. If the connection fails, check the firewall, IP address, and access permissions.
- Verify Repository: Run `kopia repository list` to confirm that the repository has been successfully created.
- Check Backup Schedule: Use `kopia schedule list` to view the configured backup schedules. Ensure that the schedule is active.
- Test Backup: Perform a manual backup using `kopia snapshot create /path/to/data` and verify that the data is successfully backed up to the repository.
If issues arise, check the Kopia logs using `kopia log show`. The logs provide detailed error information to help identify the cause. Common issues include rejected SFTP connections (due to firewall or incorrect login credentials), insufficient access permissions to the destination directory, or a corrupted repository.
References and Related Links
For more information on VPS security and system protection solutions, refer to the following articles:
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
