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

如何配置Virt-Manager将快照存储至第四台远程服务器?

Two Ways to Store KVM Snapshots on Remote Server 4

Got it, let's break this down into two practical approaches based on your needs—either saving snapshots directly to Server 4 as you create them, or syncing local snapshots over afterward. Both are straightforward to set up with Virt-Manager and standard Linux tools.

This method configures Virt-Manager to use a remote shared storage pool on Server 4, so snapshots go straight there without hitting local storage first.

Step 1: Set Up Shared Storage on Server 4

We'll use NFS (most common for Linux environments) as an example—SMB works too if you prefer that.

  • On Server 4:

    1. Install NFS server: sudo apt install nfs-kernel-server (Debian/Ubuntu) or sudo dnf install nfs-utils (RHEL/CentOS/Fedora)
    2. Create a directory for snapshots: sudo mkdir -p /srv/vm-snapshots
    3. Edit the NFS exports file: sudo nano /etc/exports
      Add this line (replace 192.168.1.0/24 with your KVM hosts' subnet):
      /srv/vm-snapshots 192.168.1.0/24(rw,sync,no_root_squash)
      
    4. Restart NFS to apply changes: sudo systemctl restart nfs-server
  • On each of your 3 KVM hosts:

    1. Install NFS client: sudo apt install nfs-common or sudo dnf install nfs-utils
    2. Create a local mount point: sudo mkdir -p /mnt/server4-snapshots
    3. Mount the remote NFS share: sudo mount -t nfs server4-ip:/srv/vm-snapshots /mnt/server4-snapshots
    4. Make the mount permanent (add to /etc/fstab):
      Edit /etc/fstab and add:
      server4-ip:/srv/vm-snapshots /mnt/server4-snapshots nfs defaults 0 0
      
      Test it with sudo mount -a to ensure no errors.

Step 2: Add the Remote Storage Pool to Virt-Manager

  1. Open Virt-Manager on your KVM host.
  2. Go to Edit > Connection Details > Storage tab.
  3. Click the + button (Add Pool) in the bottom left.
  4. Name the pool (e.g., Server4-Snapshots), select Directory as the type, then click Forward.
  5. For the Target Path, browse to /mnt/server4-snapshots and click Finish.

Step 3: Create Snapshots to the Remote Pool

  1. Open the virtual machine's details window.
  2. Switch to the Snapshots tab.
  3. Click the + button (Create Snapshot).
  4. In the popup window, use the Storage dropdown to select your Server4-Snapshots pool.
  5. Name your snapshot and click Finish—your snapshot will be saved directly to Server 4.

Approach 2: Sync Local Snapshots to Server 4 Automatically

If you prefer keeping local snapshots as a backup and syncing them to Server 4 later, this method uses rsync and cron (or inotify for real-time sync).

Step 1: Set Up Passwordless SSH Access to Server 4

This lets your KVM hosts sync files without entering a password every time.

  1. On each KVM host, generate an SSH key pair (press enter for all prompts):
    ssh-keygen -t ed25519
    
  2. Copy the public key to Server 4 (replace user and server4-ip with your details):
    ssh-copy-id user@server4-ip
    
  3. Test the connection to confirm it works without a password: ssh user@server4-ip

Step 2: Create a Sync Script

  1. Create a script file (e.g., sync-snapshots.sh) with the following content:
    #!/bin/bash
    # Local directory where Virt-Manager stores snapshots (default below—adjust if you use custom pools)
    LOCAL_SNAP_DIR="/var/lib/libvirt/images"
    # Remote directory on Server 4
    REMOTE_DIR="user@server4-ip:/srv/vm-snapshots"
    
    # Sync only snapshot files (qcow2 is the default format; adjust if you use raw)
    rsync -avz --delete --include='*.qcow2' --exclude='*' "$LOCAL_SNAP_DIR/" "$REMOTE_DIR"
    
  2. Make the script executable: chmod +x sync-snapshots.sh

Step 3: Automate the Sync

Option A: Scheduled Sync with Cron

  1. Open your crontab editor: crontab -e
  2. Add a line to run the script at your desired interval. For example, to sync every day at 2 AM:
    0 2 * * * /path/to/sync-snapshots.sh
    
    Save and exit—cron will handle the rest.

Option B: Real-Time Sync with Inotify

If you want snapshots to sync immediately after creation, use inotify-tools to monitor the local snapshot directory:

  1. Install inotify-tools: sudo apt install inotify-tools or sudo dnf install inotify-tools
  2. Modify your sync script to listen for file changes:
    #!/bin/bash
    LOCAL_SNAP_DIR="/var/lib/libvirt/images"
    REMOTE_DIR="user@server4-ip:/srv/vm-snapshots"
    
    # Listen for new/modified files and sync qcow2 snapshots
    inotifywait -m -e create -e modify "$LOCAL_SNAP_DIR" | while read dir event file; do
        if [[ $file == *.qcow2 ]]; then
            rsync -avz "$dir$file" "$REMOTE_DIR"
        fi
    done
    
  3. Set the script to run on boot (using systemd):
    • Create a systemd service file: sudo nano /etc/systemd/system/sync-snapshots.service
      [Unit]
      Description=Sync KVM snapshots to Server 4
      After=network.target
      
      [Service]
      User=root
      ExecStart=/path/to/sync-snapshots.sh
      Restart=always
      
      [Install]
      WantedBy=multi-user.target
      
    • Enable and start the service:
      sudo systemctl daemon-reload
      sudo systemctl enable --now sync-snapshots.service
      

Quick Notes

  • Make sure Server 4 has enough storage space—snapshots can be nearly as large as your VM disks, especially if you use full snapshots.
  • For NFS, ensure your network is stable; a dropped connection during snapshot creation can corrupt the file.
  • If you use SMB instead of NFS, adjust the mount command on KVM hosts to:
    sudo mount -t cifs //server4-ip/snapshots /mnt/server4-snapshots -o username=your-user,password=your-pass
    

内容的提问来源于stack exchange,提问作者xav

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:55:45