{"id":749,"date":"2023-06-14T00:14:08","date_gmt":"2023-06-13T22:14:08","guid":{"rendered":"https:\/\/petr.maxbox.cz\/?p=749"},"modified":"2023-06-14T00:44:04","modified_gmt":"2023-06-13T22:44:04","slug":"wake-on-lan-proxmox-backup-server","status":"publish","type":"post","link":"https:\/\/petr.maxbox.cz\/index.php\/2023\/06\/14\/wake-on-lan-proxmox-backup-server\/","title":{"rendered":"Wake-on-LAN Proxmox Backup Server"},"content":{"rendered":"\n<p>Inspired by <a href=\"https:\/\/wiki.archlinux.org\/title\/Wake-on-LAN\">https:\/\/wiki.archlinux.org\/title\/Wake-on-LAN<\/a><\/p>\n\n\n\n<ol class=\"wp-block-createwithrani-superlist-block ol\">\n<li class=\"wp-block-createwithrani-superlist-item\">\n<p><strong>Enable Wake on LAN (Power ON By PME) in BIOS on the target computer motherboard<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"310\" src=\"https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/IMG_20230609_073131_029-1024x310.jpg\" alt=\"\" class=\"wp-image-619\" srcset=\"https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/IMG_20230609_073131_029-1024x310.jpg 1024w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/IMG_20230609_073131_029-300x91.jpg 300w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/IMG_20230609_073131_029-768x232.jpg 768w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/IMG_20230609_073131_029-1536x465.jpg 1536w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/IMG_20230609_073131_029-2048x620.jpg 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>&nbsp;<\/p>\n<\/li>\n\n\n\n<li class=\"wp-block-createwithrani-superlist-item\">\n<p><strong>Enable WoL on the network adapter of the target computer (Linux)<\/strong><br>Depending on the hardware, the network driver may have WoL switched off by default.<br>To query this status or to change the settings, install&nbsp;<a href=\"https:\/\/archlinux.org\/packages\/?name=ethtool\">ethtool<\/a>, determine the name of the&nbsp;<a href=\"https:\/\/wiki.archlinux.org\/title\/Network_interface\">network interface<\/a>, and query it using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ethtool enp1s0 | grep Wake-on\nSupports Wake-on: pumbag\nWake-on: d<\/code><\/pre>\n\n\n\n<p>The&nbsp;Wake-on&nbsp;values define what activity triggers wake up:&nbsp;d&nbsp;(disabled),&nbsp;p&nbsp;(PHY activity),&nbsp;u&nbsp;(unicast activity),&nbsp;m&nbsp;(multicast activity),&nbsp;b&nbsp;(broadcast activity),&nbsp;a&nbsp;(ARP activity), and&nbsp;g&nbsp;(magic packet activity). The value&nbsp;g&nbsp;is required for WoL to work, if not, the following command enables the WoL feature in the driver:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ethtool -s enp1s0 wol g<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n<\/li>\n\n\n\n<li class=\"wp-block-createwithrani-superlist-item\">\n<p><strong>Find MAC addres of the network card on the target computer<\/strong><br>To trigger WoL on a target machine, its&nbsp;<strong>MAC address<\/strong> must be known. <br>To obtain it, execute the following command on the target machine:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ip link\n1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n2: enp1s0: &lt;BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000 link\/ether <b><span style=\"color: red;\">48:05:ca:09:0e:6a<\/span><\/b> brd ff:ff:ff:ff:ff:ff<\/code><\/pre>\n<\/li>\n\n\n\n<li class=\"wp-block-createwithrani-superlist-item\">\n<p><strong>Make <strong>WoL on the network adapter of the target computer<\/strong><\/strong><strong> persistent using systemd.link<\/strong><br>Link-level configuration is possible through systemd-networkd#link files. <br>The actual setup is performed by the net_setup_link udev builtin.<br>Make a file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/systemd\/network\/50-wired.link<\/code><\/pre>\n\n\n\n<p id=\"block-7e3bca46-e95b-4b5d-b2f3-d61ede374d46\">with the following content<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Match]\nMACAddress=aa:bb:cc:dd:ee:ff\n\n&#91;Link]\nNamePolicy=kernel database onboard slot path\nMACAddressPolicy=persistent\nWakeOnLan=magic<\/code><\/pre>\n<\/li>\n\n\n\n<li class=\"wp-block-createwithrani-superlist-item\">\n<p><strong>Test the setup<\/strong><br>On the target machine us netcat (nc) :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nc -ulp 9 | hexdump<\/code><\/pre>\n\n\n\n<p>On the client machine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wakeonlan 50:46:5d:a3:93:20<\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wakeonlan -i 192.168.0.201 50:46:5d:a3:93:20<\/code><\/pre>\n\n\n\n<p>On the target machine you should see something similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0000000 ffff ffff ffff 4650 a35d 2093 4650 a35d\n0000010 2093 4650 a35d 2093 4650 a35d 2093 4650\n0000020 a35d 2093 4650 a35d 2093 4650 a35d 2093\n0000030 4650 a35d 2093 4650 a35d 2093 4650 a35d\n0000040 2093 4650 a35d 2093 4650 a35d 2093 4650\n0000050 a35d 2093 4650 a35d 2093 4650 a35d 2093<\/code><\/pre>\n\n\n\n<p>Shut down the target machine issuing command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shutdown -h now<\/code><\/pre>\n\n\n\n<p>or remotely<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/bin\/ssh -t root@192.168.0.201 'shutdown -h now'<\/code><\/pre>\n\n\n\n<p>!!! DO NOT USE <big><code><code><\/code><\/code><strong>halt<\/strong> <\/big>COMMAND !!! to shut down target machine. <code><big><code><code><\/code><\/code><strong>halt<\/strong><\/big> <\/code>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.<\/p>\n\n\n\n<p>On the client machine execute again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wakeonlan 50:46:5d:a3:93:20<\/code><\/pre>\n\n\n\n<p>You should see target machine start to boot<\/p>\n\n\n\n<p><strong>Configure Proxmox Backup Server<\/strong><\/p>\n\n\n\n<p>Add an <a href=\"https:\/\/pbs.proxmox.com\/docs\/user-management.html#api-tokens\">API token <\/a>(and record the API token secret &#8211; it will only be displayed once)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"867\" height=\"255\" src=\"https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-30.png\" alt=\"\" class=\"wp-image-701\" srcset=\"https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-30.png 867w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-30-300x88.png 300w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-30-768x226.png 768w\" sizes=\"(max-width: 867px) 100vw, 867px\" \/><\/figure>\n\n\n\n<p>Add <code>\/<\/code> or <code>\/system\/tasks<\/code> permission (path) for created token<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"238\" src=\"https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-45-1024x238.png\" alt=\"\" class=\"wp-image-700\" srcset=\"https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-45-1024x238.png 1024w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-45-300x70.png 300w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-45-768x179.png 768w, https:\/\/petr.maxbox.cz\/wp-content\/uploads\/2023\/06\/Screenshot-from-2023-06-12-08-52-45.png 1191w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>Than following request should return the number of active backup tasks (if backup task is not running 0 is returned)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>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<\/code><\/pre>\n\n\n\n<p>You should modify above mentioned request using info on the proxmox web<\/p>\n\n\n\n<p><a href=\"https:\/\/pbs.proxmox.com\/docs\/api-viewer\/index.html#\/nodes\/{node}\/tasks\">https:\/\/pbs.proxmox.com\/docs\/api-viewer\/index.html#\/nodes\/{node}\/tasks<\/a><\/p>\n\n\n\n<p>Instead of about mentioned bash curl command you can use python script to test if backup task is not running<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; auto-links: false; gutter: true; title: ; quick-code: false; notranslate\" title=\"\">\nimport requests\nimport time\nimport subprocess\n\nimport warnings\nfrom urllib3.exceptions import InsecureRequestWarning\n\n# Suppress the InsecureRequestWarning\nwarnings.filterwarnings(&quot;ignore&quot;, category=InsecureRequestWarning)\n\nurl = &#039;https:\/\/192.168.0.201:8007\/api2\/json\/nodes\/localhost\/tasks?running=true&#039;\nheaders = {&#039;Authorization&#039;: &#039;PBSAPIToken=root@pam!testN:424e33be-7bc1-44c6-82b7-474860adb495&#039;}\n\ncount = 0\n\nwhile True:\n    try:\n        response = requests.get(url, headers=headers, verify=False)\n        data = response.json()\n        total = data&#x5B;&#039;total&#039;]\n\n        print(f&quot;Total: {total}&quot;)\n\n        if total == 0:\n            count += 1\n        else:\n            count = 0\n\n        if count == 10:\n            print(&quot;10 consecutive occurrences of total being 0.&quot;)\n            break\n\n    except requests.exceptions.RequestException as e:\n        if &quot;No route to host&quot; in str(e):\n            print(&quot;No route to host. Exiting the loop.&quot;)\n            break\n        else:\n            raise e\n\n    time.sleep(5)\n\nif count == 10:\n    command = &#x5B;&quot;\/usr\/bin\/ssh&quot;, &quot;-t&quot;, &quot;root@192.168.0.201&quot;, &quot;shutdown&quot;, &quot;-h&quot;, &quot;now&quot;]\n\n    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)\n    output, error = process.communicate()\n\n    if process.returncode == 0:\n        print(&quot;Command executed successfully.&quot;)\n    else:\n        print(&quot;An error occurred while executing the command.&quot;)\n        if error is not None:\n            print(&quot;Error:&quot;, error.decode())\n<\/pre><\/div><\/li>\n\n\n\n<p>than, you can write in to the \/etc\/crontab following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>40 23 * * *     root    \/usr\/bin\/wakeonlan 50:46:5d:a3:93:20 &gt; \/dev\/null 2&gt;&amp;1\n#\n1 0 * * *\troot\t\/usr\/bin\/python3 \/root\/shutDownPBS.py &gt;&gt; \/var\/log\/pbsShutDown.log 2&gt;&amp;1 \n#<\/code><\/pre>\n<\/ol>\n\n\n<p><!-- \/wp:createwithrani\/superlist-block --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>&nbsp;<\/p>\n<p><!-- \/wp:paragraph --><\/p>","protected":false},"excerpt":{"rendered":"<p>Inspired by https:\/\/wiki.archlinux.org\/title\/Wake-on-LAN &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-nezarazene"],"_links":{"self":[{"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/comments?post=749"}],"version-history":[{"count":17,"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":768,"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/posts\/749\/revisions\/768"}],"wp:attachment":[{"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/petr.maxbox.cz\/index.php\/wp-json\/wp\/v2\/tags?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}