You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无服务商快照及备份功能的全新Ubuntu VPS备份与恢复方法问询

无服务商快照及备份功能的全新Ubuntu VPS备份与恢复方法问询

Hey there! Totally get your anxiety—having a fresh VPS without built-in backup/snapshot tools feels risky when you want to tweak things. The good news is, you absolutely can back up this pristine Ubuntu install and restore it to its original state later. Let me walk you through two reliable methods, step by step.

方法一:磁盘镜像级备份(dd命令)

This creates an exact copy of your entire disk, perfect for a full "factory reset" later.

  • First, identify your VPS's main disk device. Run this command and look for the disk that matches your VPS's storage size (usually /dev/vda or /dev/sda):
    lsblk
    
  • Next, create the disk image. Important: Don't save this image on the VPS itself—if the VPS fails, you'll lose the backup. Run:
    sudo dd if=/dev/vda of=ubuntu_fresh.img bs=4M status=progress
    
    • if=/dev/vda: Replace with your disk device from the first step
    • bs=4M: Speeds up the process by using larger block sizes
    • status=progress: Shows you real-time transfer progress
  • Finally, copy the image to your local computer or another secure storage server using scp:
    scp root@your_vps_ip:/ubuntu_fresh.img /your/local/computer/path/
    
    Enter your VPS root password when prompted, and wait for the transfer to finish (time depends on disk size and internet speed).

方法二:文件级备份(tar命令)

This backs up only the actual system files (not empty disk space), so it's much smaller than a disk image. Great if you want a lightweight backup.

  • First, create the compressed backup archive. We'll exclude temporary/virtual directories that don't need backing up (they regenerate on boot):
    sudo tar -czpf ubuntu_fresh_backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run /
    
    • -czpf: Compresses the archive, preserves file permissions, and sets the output filename
    • --exclude: Skips system directories that don't hold persistent data
  • Copy the archive to your local machine with scp:
    scp root@your_vps_ip:/ubuntu_fresh_backup.tar.gz /your/local/computer/path/
    

恢复到全新状态的步骤

Before restoring, you'll need to access your VPS in rescue mode (most providers offer this option in their control panel) or boot from an Ubuntu Live CD ISO (if allowed). You can't restore a running system directly.

恢复dd磁盘镜像

  • Once in rescue mode, confirm your disk device again with lsblk.
  • Copy your local backup image to the rescue environment:
    scp /your/local/computer/path/ubuntu_fresh.img root@your_rescue_vps_ip:/tmp/
    
  • Overwrite the disk with the backup (this will erase all current data on the VPS—double-check your disk device!):
    sudo dd if=/tmp/ubuntu_fresh.img of=/dev/vda bs=4M status=progress
    
  • Reboot your VPS, and it'll boot back into the original fresh Ubuntu state.

恢复tar文件备份

  • In rescue mode, mount your VPS's system partition to a temporary directory (replace /dev/vda1 with your actual system partition from lsblk):
    sudo mount /dev/vda1 /mnt
    
  • Copy your local tar archive to the mounted partition:
    scp /your/local/computer/path/ubuntu_fresh_backup.tar.gz root@your_rescue_vps_ip:/mnt/
    
  • Extract the archive to restore the system files:
    sudo tar -xzf /mnt/ubuntu_fresh_backup.tar.gz -C /mnt
    
  • Fix the GRUB bootloader (it might break after restoration):
    # Bind system directories to the mounted partition
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys
    # Enter the chroot environment
    sudo chroot /mnt
    # Reinstall GRUB and update boot config
    grub-install /dev/vda
    update-grub
    # Exit chroot
    exit
    
  • Unmount all directories and reboot:
    sudo umount /mnt/dev
    sudo umount /mnt/proc
    sudo umount /mnt/sys
    sudo umount /mnt
    sudo reboot
    

Quick Tips

  • Before backing up, switch to multi-user mode to minimize file locks: sudo systemctl isolate multi-user.target
  • Store backups in at least one external location (local computer + cloud storage is ideal)
  • The dd method is slower but creates a perfect replica, while tar is faster and uses less storage

备注:内容来源于stack exchange,提问作者Putu Ardi Dharmayasa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 12:15:30