On Linux, there is no single ‘backup button’: the appropriate method varies depending on the type of data. Files must be copied or archived, databases must be exported using their own backup tools, and a snapshot of the entire system can be taken. Below, we outline the most common methods and how to restore them. Our article on VPS backups covers backup strategy (what, where and how often).
1. Copying files using rsync
rsync only copies files that have changed, making it ideal for regular backups. It preserves permissions, owners and dates, and can also copy files to another machine via SSH:
# Helyi mentés egy másik lemezre
rsync -a /var/www/ /mnt/mentes/www/
# Mentés egy távoli szerverre SSH-n keresztül
rsync -az /var/www/ mentes@backup.example.com:/mentesek/www/
During restoration, the source and destination swap places:
rsync -a mentes@backup.example.com:/mentesek/www/ /var/www/
Please note the slash at the end of the source path: /var/www/ copies the contents of the folder, whilst /var/www copies the folder itself. For further details, see the article on copying files between servers.
2. Archiving with tar
If you wish to preserve the complete status of a given point in time in a single file, create a compressed archive:
# Mentés
tar -czf /mentes/www-$(date +%F).tar.gz -C /var www
# Visszaállítás
tar -xzf /mentes/www-2026-10-26.tar.gz -C /var
The date in the filename helps to distinguish between different backups. For more details: creating and extracting tar.gz archives.
3. Backup of databases
Copying the files of a running database does not provide a reliable backup, as they continue to change whilst being copied. Use the database management system’s own tool:
# MariaDB mentés (MySQL-en: mysqldump)
mariadb-dump --single-transaction --routines adatbazis | gzip > adatbazis.sql.gz
# Visszaállítás (MySQL-en: mysql)
gunzip < adatbazis.sql.gz | mariadb adatbazis
# PostgreSQL mentés és visszaállítás
pg_dump -Fc adatbazis > adatbazis.dump
pg_restore -d adatbazis adatbazis.dump
The --single-transaction switch saves a consistent state without locking for InnoDB tables. In newer versions of MariaDB, the command is called mariadb-dump; the old name mysqldump still works for the time being, but MariaDB marks it as deprecated; during testing, MariaDB 11.8 displayed the following message on every run: mysqldump: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-dump' instead. The backup and restore described above ran without error on a test database (AlmaLinux 9, MariaDB 11.8), and every row was present in the restored table. The article ‘Installing the MariaDB database server’ covers the installation of MariaDB.
4. Snapshot
A snapshot captures the state of the entire disk at a given moment, so that the whole system can be quickly restored following a faulty update. On Linux, LVM can also create snapshots, whilst on virtual servers, the virtualisation layer can do so as well (see: What is a snapshot?). The snapshot is typically stored on the same storage device as the original data; therefore, it does not replace a backup made to a different location.
5. Automation
Manual backups will inevitably be neglected at some point. Encapse the commands above in a script and run it regularly as a cron job. For larger amounts of data, it is advisable to use a tool specifically designed for backups (such as restic or BorgBackup), which encrypt the data, store only the changes and manage old backups as well.
Check the restoration
The backup is only useful if it can be restored. From time to time, restore a backup to a test directory or a test database, and check that the files are complete and that the database can be loaded. For archives, the command tar -tzf mentes.tar.gz lists the contents without extracting them, whilst gzip -t checks the integrity of the compressed file.
If you do not wish to deal with backups and server maintenance, our system administrators will take care of this as part of our managed VPS service.