So, while I was on vacation, my Proxmox Backup Server boot drive failed! No problem, I take backups of the server itself …. onto the backup server. So in this video, I’m going to start from a clean PBS install, mount my intact backup pool, and then restore the PBS configs out of the backup.

Video

Thumbnail

Restoring the Datastore

First, we need to mount the data disks. In my case, they are a zfs pool named backup, so we use zpool import -f backup to import the pool. Once the pool is imported, the directories should show up (you can find them with zfs list if you forgot where they are).

If you’re using non-zfs, you’ll probably have to write a line in /etc/fstab and mount them the traditional way.

Now, to get PBS to find the dataset on a brand new PBS system, we need to create a datastore.cfg which points to the directory of the datastore. That file won’t exist if we have no datastores, so create it (/etc/proxmox-backup/datastore.cfg) with the following contents:

datastore: <name>
    path /path/to/your/backups

Refresh in the GUI and it should appear, and you should be able to access your backups at this point (although user accounts and such aren’t back yet).

Restore the Backup

Since we are running on the PBS host, we have access to PBS client (the binary is installed) and we can just point it at localhost. We won’t need the fingerprint to trust localhost, but we will need a username and password, and the long full name of the backup (the one with the date in it). Here’s the command I used to mount the backup temporarily:

#Create a directory to mount at (this can't exist already)
mkdir -p /mnt/backup
#Call the backup client
proxmox-backup-client mount host/bigstor/2024-05-04T04:00:58Z root.pxar /mnt/backup --repository localhost:backup

At that point, we can rsync the contents of /etc/proxmox-backup from the backup into its old home. It’s critical that you use rsync and not cp to do this, since cp will not retain file permissions!

#Copy data from backup
rsync -r -v /mnt/backup/etc/proxmox-backup/ /etc/proxmox-backup/

At this point I would unmount the backup (unmount /mnt/backup) and restart the services. Make sure they come up fine. Also, delete pre-existing temporary files that were in the backup.

#Delete temp files
rm -rf /etc/proxmox-backup/.*
#Restart proxmox backup
systemctl restart proxmox-backup
systemctl restart proxmox-backup-proxy
#If you need to look at logs:
journalctl -xeu proxmox-backup
journalctl -xeu proxmox-backup-proxy

Now that this is done, I copied the remaining files on the system out of the backup (my autoshutdown scripts and other systemd units). You may have authentication errors with proxmox-backup-client after restoring since sessions will be terminated (we deleted those session temp files), so you will need to run proxmox-backup-client logout to clear the client’s session cache and start over.

Auto-Backup Scripts

Here’s the script I use for autobackup. It’s a systemd service unit + systemd timer. I use this script on a lot of my Debian systems which are not part of PVE.

The service (/etc/systemd/system/autobackup.service):

[Unit]
Description=Run Backup to Proxmox Backup Server
After=network-online.target

[Service]
#Technically if we are on localhost we can skip the fingerprint
Environment=PBS_FINGERPRINT=your_fingerptint
#Your API key here
Environment=PBS_PASSWORD=api_key_here
#Use your user @ realm ! api key name @ hostname : repository
Environment=PBS_REPOSITORY=user@pbs!apikey@localhost:backup
Type=oneshot
#Backup the root fs. This will not backup any other mount points, only the mount point which mounts /
#You can add more pxars if you want more mount points
ExecStart=proxmox-backup-client backup root.pxar:/

[Install]
WantedBy=default.target

And the timer (/etc/systemd/system/autobackup.timer):

[Unit]
Description=Backup System Daily
RefuseManualStart=no
RefuseManualStop=no

[Timer]
#Run 540 seconds after boot for the first time
#Since I shutdown every night, this will be every day
OnBootSec=540
#Run at midnight UTC
#If you don't shutdown every night, uncomment this instead
#OnCalendar=*-*-* 00:00:00
Unit=autobackup.service

[Install]
WantedBy=timers.target

And finally, we enable the timer, not the service:

systemctl daemon-reload
systemctl enable --now autobackup.timer

All done! You can test it by running systemctl start autobackup which will run a backup now.