Wake-on-LAN Proxmox Backup Server

Inspired by https://wiki.archlinux.org/title/Wake-on-LAN

  1. Enable Wake on LAN (Power ON By PME) in BIOS on the target computer motherboard

     

  2. Enable WoL on the network adapter of the target computer (Linux)
    Depending on the hardware, the network driver may have WoL switched off by default.
    To query this status or to change the settings, install ethtool, determine the name of the network interface, and query it using the command:

    # ethtool enp1s0 | grep Wake-on
    Supports Wake-on: pumbag
    Wake-on: d

    The Wake-on values define what activity triggers wake up: d (disabled), p (PHY activity), u (unicast activity), m (multicast activity), b (broadcast activity), a (ARP activity), and g (magic packet activity). The value g is required for WoL to work, if not, the following command enables the WoL feature in the driver:

    # ethtool -s enp1s0 wol g

    This command might not last beyond the next reboot and in this case must be repeated via some mechanism. Common solutions are listed in the following subsections.

  3. Find MAC addres of the network card on the target computer
    To trigger WoL on a target machine, its MAC address must be known.
    To obtain it, execute the following command on the target machine:

    $ ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp1s0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000 link/ether 48:05:ca:09:0e:6a brd ff:ff:ff:ff:ff:ff
  4. Make WoL on the network adapter of the target computer persistent using systemd.link
    Link-level configuration is possible through systemd-networkd#link files.
    The actual setup is performed by the net_setup_link udev builtin.
    Make a file

    /etc/systemd/network/50-wired.link

    with the following content

    [Match]
    MACAddress=aa:bb:cc:dd:ee:ff
    
    [Link]
    NamePolicy=kernel database onboard slot path
    MACAddressPolicy=persistent
    WakeOnLan=magic
  5. Test the setup
    On the target machine us netcat (nc) :

    nc -ulp 9 | hexdump

    On the client machine

    wakeonlan 50:46:5d:a3:93:20

    or

    wakeonlan -i 192.168.0.201 50:46:5d:a3:93:20

    On the target machine you should see something similar to this:

    0000000 ffff ffff ffff 4650 a35d 2093 4650 a35d
    0000010 2093 4650 a35d 2093 4650 a35d 2093 4650
    0000020 a35d 2093 4650 a35d 2093 4650 a35d 2093
    0000030 4650 a35d 2093 4650 a35d 2093 4650 a35d
    0000040 2093 4650 a35d 2093 4650 a35d 2093 4650
    0000050 a35d 2093 4650 a35d 2093 4650 a35d 2093

    Shut down the target machine issuing command

    shutdown -h now

    or remotely

    /usr/bin/ssh -t root@192.168.0.201 'shutdown -h now'

    !!! DO NOT USE halt COMMAND !!! to shut down target machine. halt command puts the system into complete power-off mode, cutting out power supply on the machine completely, so network card can not communicate with network.

    On the client machine execute again:

    wakeonlan 50:46:5d:a3:93:20

    You should see target machine start to boot

    Configure Proxmox Backup Server

    Add an API token (and record the API token secret – it will only be displayed once)

    Add / or /system/tasks permission (path) for created token

    Than following request should return the number of active backup tasks (if backup task is not running 0 is returned)

    curl -s -k -H 'Authorization: PBSAPIToken=root@pam!testN:424e33be-7bc1-44c6-82b7-474860adb495' https://192.168.0.201:8007/api2/json/nodes/localhost/tasks\?running=true | jq .total

    You should modify above mentioned request using info on the proxmox web

    https://pbs.proxmox.com/docs/api-viewer/index.html#/nodes/{node}/tasks

    Instead of about mentioned bash curl command you can use python script to test if backup task is not running

    import requests
    import time
    import subprocess
    
    import warnings
    from urllib3.exceptions import InsecureRequestWarning
    
    # Suppress the InsecureRequestWarning
    warnings.filterwarnings("ignore", category=InsecureRequestWarning)
    
    url = 'https://192.168.0.201:8007/api2/json/nodes/localhost/tasks?running=true'
    headers = {'Authorization': 'PBSAPIToken=root@pam!testN:424e33be-7bc1-44c6-82b7-474860adb495'}
    
    count = 0
    
    while True:
        try:
            response = requests.get(url, headers=headers, verify=False)
            data = response.json()
            total = data['total']
    
            print(f"Total: {total}")
    
            if total == 0:
                count += 1
            else:
                count = 0
    
            if count == 10:
                print("10 consecutive occurrences of total being 0.")
                break
    
        except requests.exceptions.RequestException as e:
            if "No route to host" in str(e):
                print("No route to host. Exiting the loop.")
                break
            else:
                raise e
    
        time.sleep(5)
    
    if count == 10:
        command = ["/usr/bin/ssh", "-t", "root@192.168.0.201", "shutdown", "-h", "now"]
    
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
        output, error = process.communicate()
    
        if process.returncode == 0:
            print("Command executed successfully.")
        else:
            print("An error occurred while executing the command.")
            if error is not None:
                print("Error:", error.decode())
    
  6. than, you can write in to the /etc/crontab following

    40 23 * * *     root    /usr/bin/wakeonlan 50:46:5d:a3:93:20 > /dev/null 2>&1
    #
    1 0 * * *	root	/usr/bin/python3 /root/shutDownPBS.py >> /var/log/pbsShutDown.log 2>&1 
    #

 

Proxmox Backup Server configuration

Original here: https://www.thomas-krenn.com/en/wiki/Proxmox_Backup_Server_configuration

BUY PROXMOX BACKUP SERVER SUBSCRIPTIONS

After successful installation of the Proxmox Backup Server the configuration via the web interface can be done (https://IP:8007). Be sure to specify the port correctly. This article shows which steps are necessary to set up a Proxmox Backup Server.

Buy Proxmox Backup Server Subscriptions

Contents

  1. Create ZFS Pool & Create Datastore
  2. Prune & Garbage Collection configuration
  3. Create & store backup user
  4. Add Proxmox Backup Server
  5. Perform Proxmox Test Backup

Create ZFS Pool & Create Datastore

In this section, we will show you how to create a ZFS pool and backup datastore.

First you have to initialize all disks you want to use for the backup datastore with GPT, this can be done in the GUI via Administration > Storage / Disks > Initialize with GPT’ or on the command line with

sgdisk /dev/sdX
  • Then a ZFS pool is created via Administration > Storage / Disks > ZFS.
  • A name is assigned, the RAID level is selected, compression and ashift can usually be left at default values.
  • With ashift you control the block size – ashift 12 means 2 to the power of 12 = 4096B = 4K block size.
  • Then select the desired media and press OK.

In this test, we used a RAID mirror, but a RAID-10 or RAID-Z2/ RAID-Z3 can also be used for a larger number of hard disks. Proxmox recommends SSD-only for backup storage. If this is not feasible for cost reasons, we recommend the use of a ZFS Special Device (ZFS Instant Log – ZIL-Device). – for example Intel Optane. Once the pool has been created, it is automatically included in the PBS as a backup datastore. Now you can see the created datastore under Datastore > pbs-local.

Prune & Garbage Collection configuration

This section defines and sets the retention periods of the backups:

  • Under Datastore > pbs-local > Prune & GC you can set how many backups should be kept and when the garbage collection should be performed.
  • The best way to plan and orient yourself is by using the Proxmox Prune Simulator.
  • If the desired setting was found, you can set these via Edit and now the Datastore is configured.

Thomas Krenn recommends a test phase when introducing the Proxmox backup server to find the correct settings for Prune and GC. The Prune simulator helps very well here.

Explanation of Prune: Prune checks whether certain backups can be removed from the index based on the set retention periods. The index contains the information about all blocks of the backups, which could be restored to another system via the PBS. For example, if there are 6 versions of a block = 6 backups and a retention of 5 is set, Prune will delete the oldest version of the block from the index during the Prune Schedule, so that the retention is correctly maintained again and only 5 versions of the block are left. When Prune does this can be set via “Prune Schedule”. No load is created on the storage during the process, so the Prune Schedule can be executed at any time.

Explanation Garbage Collection: The garbage collector grabs the blocks excluded from the index by Prune and also deletes them from the storage. This creates load on the storage and may take longer if there are many backups. Depending on your needs, we recommend running the garbage collection once a day or once a week.

Create & store backup user

By default the user root@pam has full access. Via Configuration > Accesscontrol > User Management additional users can be created, whose rights can be restricted under Permissions. By default, every newly created user has the role NoAccess. The roles and permissions concept can be seen in the Proxmox documentation. At the datastore level, the assignment is even easier. Under Datastore > pbs-local you can assign Permissions to created users accordingly to the datastore and assign a role.

Add Proxmox Backup Server

This section explains how to add the Proxmox Backup Server in a PVE system:

  • To add the Proxmox Backup Server now to a Proxmox Single Host or a Proxmox Ceph Cluster first copy the fingerprint of the PBS in the Dashboard.
  • Then go to the PVE system or PVE cluster and add the Proxmox Backup Server under Datacenter > Storage > Add > Proxmox Backup Server.
  • Under ID one assigns the Proxmox-VE local datastore ID, Server one specifies the IP address or the host name of the Proxmox Backup Server.
  • Username you have to specify the LOCAL Proxmox-VE-PAM User, here is root not enough. Here in our test scenario this is root@pam.
  • Under Datastore enter the name of the datastore of the Proxmox Backup Server.
  • Finally add the copied fingerprint of the PBS and add the server to Proxmox VE with Add.

Perform Proxmox Test Backup

Now that the PBS is stored in the Proxmox VE system, you can perform a test backup. The best way to do this is to perform a one-time backup by clicking either on a container or on a VM and selecting Backup > Backup now. Please note the different backup modes, which are well described in the Proxmox documentation. After a successful backup you can see the backup in the PVE in the GUI as well as on the Proxmox Backup Server.