1. Decide what must be recoverable

Separate application data, configuration, databases, secrets and operating-system state. A list of files is not a recovery plan: document the restore order, dependencies, credentials and acceptable recovery point.

中文说明:备份的目标不是“生成压缩包”,而是在机器损坏或误操作后能按步骤恢复服务。

2. Create a timestamped archive

sudo tar --acls --xattrs -czf /root/etc-$(date +%F-%H%M).tar.gz /etc
sudo tar -tzf /root/etc-$(date +%F-%H%M).tar.gz | head

Store the generated filename in a variable so the archive can be verified without reconstructing its timestamp:

BACKUP="/root/etc-$(date +%F-%H%M%S).tar.gz"
sudo tar --acls --xattrs -czf "$BACKUP" /etc
sudo tar -tzf "$BACKUP" | head
sudo sha256sum "$BACKUP"

3. Copy backups off the server

scp root@SERVER_IP:/root/etc-YYYY-MM-DD-HHMMSS.tar.gz ./

Run this from your trusted workstation and replace the filename exactly. Prefer a dedicated backup account and encrypted storage. Do not expose archives containing private keys or credentials.

4. Test extraction into a temporary directory

sudo mkdir -p /root/restore-test
sudo tar -xzf /root/etc-backup.tar.gz -C /root/restore-test
sudo find /root/restore-test/etc -maxdepth 2 -type f | head

Inspect the extracted structure and compare checksums or selected files. Never test restoration by extracting over live /etc.

5. Database consistency

For databases, use their supported dump or physical-backup tools. Copying live database files with a generic tar command may produce an inconsistent backup unless the database is quiesced or the storage snapshot is coordinated.

6. Apply the 3-2-1 principle

  • Keep at least three copies of important data.
  • Use at least two different storage types or systems.
  • Keep one copy off-site or otherwise isolated.

7. Recovery drill

  1. Provision a clean test host or isolated VM.
  2. Retrieve the backup and verify its checksum.
  3. Restore configuration and data in documented order.
  4. Start services and test application-level health.
  5. Record elapsed recovery time and missing dependencies.
Backup security: configuration archives often contain passwords, API tokens, private keys and certificates. Encrypt them, restrict access and define retention.

Checklist

  • Define scope and recovery objectives.
  • Copy data off-host.
  • Verify checksums after transfer.
  • Perform regular restore tests.
  • Protect and expire old backups securely.

References & further reading

Commands are examples for a representative Ubuntu/Linux environment. Review paths, versions, access requirements and maintenance impact before applying them to production systems.