关于Hetzner云平台Ubuntu服务器全量手动备份方法的咨询
Hey there! Let’s break down exactly how to create a full manual backup of your Hetzner Ubuntu server—covering your entire system, all three WordPress sites, and their databases, all wrapped into a single file for when disaster strikes.
两种可行的全量备份方案
方案1:用Hetzner云自带的快照功能(最简单)
If you just need a reliable backup that’s easy to restore directly on Hetzner, their built-in snapshot tool is your best bet—it captures the entire server state in one go:
- Log into your Hetzner Cloud Console, find your target server.
- Click the Snapshots tab, then hit Create Snapshot.
- Give it a descriptive name (like
Full-Disaster-Recovery-2024-MM-DD) and wait for the process to finish. - This snapshot includes everything: system files, WordPress sites, databases, all configurations. If your server gets deleted later, you can spin up a new server using this snapshot and pick up right where you left off.
方案2:手动打包全量备份(适合本地存储)
If you want a backup file you can download and store locally (or elsewhere), follow these steps to pack everything into one compressed file:
Step 1: Prep for backup
First, stop running services to avoid data inconsistencies (like a WordPress post being written mid-backup):
# Stop your web server (nginx or apache2, use the one you have) sudo systemctl stop nginx # Or sudo systemctl stop apache2 # Stop MySQL to freeze database state sudo systemctl stop mysql
Step 2: Export all WordPress databases
Grab your database credentials from the wp-config.php file of each WordPress site, then export all databases (you can export all at once if you prefer):
# Export all databases to a single SQL file mysqldump -u YOUR_DB_USERNAME -pYOUR_DB_PASSWORD --all-databases > /tmp/wordpress_backup.sql
Note: Replace
YOUR_DB_USERNAMEandYOUR_DB_PASSWORDwith actual values from your wp-config.php. Skip the space between-pand your password to avoid a prompt.
Step 3: Pack the entire system + databases into one file
Use tar to compress everything, excluding temporary/system virtual directories that don’t need backing up:
sudo tar -cvpzf /full_server_backup.tar.gz \ --exclude=/dev \ --exclude=/proc \ --exclude=/sys \ --exclude=/tmp \ --exclude=/run \ --exclude=/mnt \ --exclude=/media \ --exclude=/lost+found \ --exclude=/full_server_backup.tar.gz \ / /tmp/wordpress_backup.sql
Let’s break down the flags:
-c: Create a new archive-v: Show progress (optional, remove it for faster backup)-p: Preserve file permissions (critical for system recovery)-z: Compress with gzip to save space-f: Specify the output file name
Step 4: Restart your services
Once the backup is done, get your sites back online:
sudo systemctl start mysql sudo systemctl start nginx # Or sudo systemctl start apache2
Step 5: Download the backup to your local machine (optional but recommended)
Use scp from your local computer to pull the backup file:
scp your_server_username@your_server_ip:/full_server_backup.tar.gz /path/on/your/local/computer/
How to restore from this backup
If your server gets deleted entirely:
- Create a new Ubuntu 20.04/22.04 server (matching your original OS version) on Hetzner.
- Upload your backup file to the new server (use
scpin reverse). - Unpack the backup:
sudo tar -xvpzf /full_server_backup.tar.gz -C / - Fix any system-specific configs (like network settings or fstab if needed), then reboot the server. You should be back to your original setup.
备注:内容来源于stack exchange,提问作者kobilevi

