How to Create a Complete Bare-Metal Backup of a CentOS Server (Including Boot Partition, Configs & Databases)


1 views

When migrating from a dedicated server to VPS, you need to consider these critical components:

  • Boot partition and MBR/GPT configuration
  • System configuration files (/etc, /var, /usr/local/etc)
  • User data and home directories
  • Package management state (rpm/yum/dnf)
  • Running services and their data (MySQL, PostgreSQL, etc.)
  • Cron jobs and systemd services

This creates a compressed archive of the entire system (excluding temporary files):

sudo tar --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found \
--exclude=/sys --exclude=/mnt --exclude=/media --exclude=/run \
--exclude=/tmp --exclude=/dev -cvpzf /backup.tar.gz /

To restore:

tar -xvpzf /backup.tar.gz -C /mnt/newroot/

For creating a bootable image of your entire disk:

sudo dd if=/dev/sda bs=4M conv=sync,noerror status=progress | gzip -c > /mnt/backup/centos_sda.img.gz

Restoration command:

gunzip -c /mnt/backup/centos_sda.img.gz | dd of=/dev/sda bs=4M status=progress

For MySQL/MariaDB:

mysqldump --all-databases --single-transaction --quick --lock-tables=false > full_backup-$(date +%F).sql -u root -p

For PostgreSQL:

pg_dumpall -U postgres > full_backup-$(date +%F).sql

Always verify backup integrity:

# For tar backups
gzip -t /backup.tar.gz && echo "OK" || echo "FAIL"

# For DD images
gunzip -t /mnt/backup/centos_sda.img.gz

Use rsync for efficient incremental backups:

rsync -aAXv --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt/backup/centos_full/

Upload your backup to S3 using AWS CLI:

aws s3 cp /backup.tar.gz s3://your-bucket-name/centos_backups/ --storage-class STANDARD_IA

Or use rclone for multiple providers:

rclone copy /backup.tar.gz remote:backup-bucket/centos/

Sample cron job for weekly full backups:

0 3 * * 0 root /usr/bin/tar --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/run --exclude=/tmp --exclude=/dev -cvpzf /backup/full-backup-$(date +\%F).tar.gz / > /var/log/backup.log 2>&1

When migrating from dedicated to VPS infrastructure, creating a complete system backup is crucial for business continuity. The ideal backup should be:

  • Bootable restoration capability
  • File-level accessibility
  • Preservation of permissions and ownership
  • Compressed storage format

The most flexible approach for full system backup while maintaining file accessibility:


sudo tar -cvpzf /backup/centos_full_backup.tar.gz \
    --exclude=/backup \
    --exclude=/proc \
    --exclude=/tmp \
    --exclude=/mnt \
    --exclude=/dev \
    --exclude=/sys \
    --exclude=/run \
    --exclude=/media \
    --one-file-system /

Key parameters explained:

  • -c: Create new archive
  • -v: Verbose output
  • -p: Preserve permissions
  • -z: gzip compression
  • --one-file-system: Avoids mounted filesystems

For creating bootable disk images when storage space is available:


sudo dd if=/dev/sda of=/backup/centos_disk.img bs=4M status=progress

For compressed network transfer:


sudo dd if=/dev/sda bs=4M | gzip -c | ssh user@backup-server "cat > /backups/centos.img.gz"

Critical step before server decommissioning:


# For tar archives
sudo tar -tvf /backup/centos_full_backup.tar.gz | less

# For dd images
sudo file /backup/centos_disk.img
sudo fdisk -l /backup/centos_disk.img

From tar archive:


sudo tar -xvpzf /backup/centos_full_backup.tar.gz -C /mnt/restore --numeric-owner

From dd image:


sudo dd if=/backup/centos_disk.img of=/dev/sda bs=4M status=progress

For production environments consider:

  • Bareos: Open-source backup solution with web interface
  • BorgBackup: Deduplicating backup program
  • Rsync: Incremental backups with hard links