Day 7: Lifecycle, Snapshots, and Backups
Goal: Power VMs off and on, resize them, attach disks while they run, undo a mistake with a snapshot, and back up and restore the database. · Duration: approx. 75 min · Prerequisite: Day 6
Briefing
| Command | What happens | Afterwards |
|---|---|---|
onevm poweroff |
VM shuts down, disks stay in the system datastore | poff, back on with resume |
onevm undeploy |
like poweroff, but the disks move back to the image datastore | unde, needs PROLOG again at start |
onevm terminate |
VM is deleted, non-persistent disks too | gone |
onevm resize |
change CPU and RAM | always when poff, while running only with hotplug |
onevm disk-attach/-detach |
attach and detach a disk while running | immediately |
onevm disk-snapshot-* |
capture a disk’s state, jump back | revert only when poff |
onevm backup |
back up the entire VM to a backup datastore | image of type BK |
Drill 1: Off, bigger, on
notes-api should get more memory and a full core:
onevm poweroff notesHalf a minute later:
onevm listExpected:
ID USER GROUP NAME STAT CPU MEM HOST TIME
22 oneadmin oneadmin db runn 0.5 512M localhost 0d 00h04
21 oneadmin oneadmin notes poff 0.5 384M localhost 0d 00h07
onevm resize notes --memory 512 --cpu 1
onevm resume notesAfter a minute and a half, once the startup script has finished:
IP=$(onevm show notes | grep -o 'ETH0_IP="[0-9.]*' | cut -d'"' -f2)
onevm list
curl -s $IP:8080/version; echo
ssh $IP "free -m | sed -n 2p"Expected (shortened):
21 oneadmin oneadmin notes runn 1 512M localhost 0d 00h09
0.7.1
Mem: 470 41 319 2 110 415
The startup script ran again at power-on and restarted the container. The VM now sees a good 470 MB; the kernel takes the rest.
Save your progress? Sign up for free
Drill 2: Hotplug
An additional disk without stopping the VM:
oneimage create --name extra --type DATABLOCK --size 128 --datastore default
onevm disk-attach notes --image extraA few seconds later:
onevm show notes | sed -n '/^VM DISKS/,/^$/p'
ssh $IP "grep -E 'sd|vd' /proc/partitions"Expected:
VM DISKS
ID DATASTORE TARGET IMAGE SIZE TYPE SAVE
0 default vda Alpine Linux 3.20 1M/512M file NO
2 default sdb extra -/128M file NO
1 - sda CONTEXT 1M/- - -
253 0 524288 vda
8 0 131072 sda
The new disk has disk ID 2. Inside the VM it is again called
sda, as on Day 3. Detaching works via the disk ID:
onevm disk-detach notes 2A few seconds later, sda has disappeared inside the VM.
The disk was not persistent, so its content is gone too. The image
extra remains.
oneimage delete extraSave your progress? Sign up for free
Drill 3: A snapshot before the mistake
Before you risk anything with the database, you capture the state of
the data disk. It is disk 1 of the VM db:
onevm disk-snapshot-create db 1 vorherA few seconds later:
onevm show db | sed -n '/^VM DISK SNAPSHOTS/,/^$/p'Expected:
VM DISK SNAPSHOTS
AC ID DISK PARENT DATE SIZE NAME
=> 0 1 -1 11/12 19:44:41 -/1024M vorher
Now a mistake happens, a note that should not go in:
curl -s -H "X-API-Key: lab-api-key-123" -d '{"text":"Versehentlich"}' $IP:8080/notes; echo
curl -s $IP:8080/notes; echoExpected (IDs will differ):
{"id":"f02d0f7d-9e33-46d9-9fcd-c99689e78a83","text":"Versehentlich"}
[{"id":"602722bb-…","text":"Hallo OpenNebula"},{"id":"f02d0f7d-…","text":"Versehentlich"}]
Back to the snapshot. That does not work while running:
onevm disk-snapshot-revert db 1 0Expected:
[one.vm.disksnapshotrevert] Could not revert to disk snapshot for VM 22, wrong state RUNNING.
A database whose disk changes underneath it would be broken immediately. So: off, back, on:
onevm poweroff dbWhen onevm list shows poff for
db:
onevm disk-snapshot-revert db 1 0
onevm resume dbAfter a minute and a half:
curl -s $IP:8080/notes; echoExpected:
[{"id":"602722bb-05ab-4559-ac6e-47609ba9ab2b","text":"Hallo OpenNebula"}]
The accidental note is gone.
Save your progress? Sign up for free
Drill 4: A backup datastore
Snapshots live on the same disk as the data. If the disk breaks, both
are gone. Backups belong somewhere else. OpenNebula 7 has its own
datastores for this. In the lab, rsync backs up to the same machine; in
production, RSYNC_HOST would be a backup server:
mkdir -p ~/one-lab/tag07
cd ~/one-lab/tag07
cat > backup.ds <<'EOF'
NAME = "backup"
TYPE = "BACKUP_DS"
DS_MAD = "rsync"
TM_MAD = "-"
RSYNC_HOST = "localhost"
RSYNC_USER = "oneadmin"
EOF
onedatastore create backup.dsExpected:
ID: 100
onevm backup db -d backupAfter a minute:
oneimage list | grep -E 'ID|BK'Expected (shortened):
ID USER GROUP NAME DATASTORE SIZE TYPE PER STAT RVMS
6 oneadmin oneadmin 22 12-Nov 19.48 backup 225M BK Yes rdy 1
An image of type BK, named after the VM ID and the time.
It contains all disks of the VM, 225 MB instead of 1.5 GB, because empty
areas are not copied. The VM kept running throughout.
Save your progress? Sign up for free
Drill 5: Restore
oneimage restore 6 -d defaultExpected:
VM Template: 6
Images: 7 8
The backup produces a template and two new images in the
default datastore:
onetemplate show 6 | grep -A1 'NIC=\['Expected:
NIC=[
IP="192.168.150.22",
NIC=[
IP="10.10.10.20",
The restored template has the same fixed IPs as the original. It
would therefore only start once db is gone; otherwise the
addresses are taken. For an emergency, that is right; for a test
alongside it, you would have to change the NICs in the template. For
now, you clean up. --recursive deletes the template’s
images along with it:
onetemplate delete 6 --recursiveSave your progress? Sign up for free
Checkpoint
onedatastore list | grep backupExpected: 100 backup with TYPE
bck.
oneimage list | grep -c ' BK 'Expected: 1.
curl -s $IP:8080/notes; echoExpected: exactly the note “Hallo OpenNebula”.
Challenge
A backup you have to remember gets forgotten. Have db
backed up every day at 3 a.m.
Note: onevm backup --help knows options
for schedules.
Solution
onevm backup db -d backup --schedule "11/13 03:00" --weekly 0,1,2,3,4,5,6
onevm show db | sed -n '/^SCHEDULED ACTIONS/,/^$/p'Expected (date and remaining time will differ):
VM 22: backup scheduled at 2026-11-13 03:00:00 +0000
SCHEDULED ACTIONS
ID ACTION ARGS SCHEDULED REPEAT END STATUS
0 backup 100,0 11/13 03:00 Weekly 0,1,2,3,4,5,6 None Next in 7.16 hours
--schedulesets the first run,--weeklythe weekdays (0 = Sunday).- The time is in UTC, which is what the server runs on.
- The schedule is attached to the VM, not to the template. A new
dbneeds it again, or the template gets aSCHED_ACTIONsection.
Save your progress? Sign up for free
Enterprise Note
- Incremental backups: With
BACKUP_CONFIG=[ MODE="INCREMENT" ]on the VM, OpenNebula only backs up changed blocks, and--resetstarts a new full backup. With large disks, that saves hours. - Backup targets: rsync is included in the Community Edition. The Enterprise Edition brings restic with encryption and deduplication, and vendors such as Veeam talk to OpenNebula directly.
- Consistency: A backup of a running database is
“crash-consistent”, as after a power failure. Postgres can handle that.
If you want it cleaner, freeze the file system with the qemu-guest-agent
(
FS_FREEZE) or additionally back up the database withpg_dump.