[SOLVED] Automtically backup Proxmox pve to pbs

Jan 31, 2021
21
1
8
59
Ich möchte einmal im Monat ein terminiertes Backup des Proxmox pve vermittels des Proxmox Backup Client durchführen. Hierzu habe ich als root auf dem Proxmox pve via crontab -e diesen Eintrag für das Backup an jedem ersten des Monats um 22:13 Uhr eingefügt:

13 22 1 * * proxmox-backup-client backup root.pxar:/

alternativ:
13 22 1 * * /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1
oder
13 22 1 * * "/usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1"

Manuell funktioniert das Backup perfekt (ich habe die Umgebungsvariablen in der.bashrc definiert). Jedoch bekomme ich den automatisierten Backupstart nicht hin.

Kann mich bitte jemand in die richtige Richtung schubsen?

I would like to perform a scheduled backup of the Proxmox pve once a month using the proxmox backup client. For this purpose I added as root this entry for the backup on the first of the month at 10:13 p.m. via crontab -e

13 22 1 * * proxmox-backup-client backup root.pxar:/

alternative:
13 22 1 * * /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1
or
13 22 1 * * "/usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1"

The backup works perfect while manually initiated (with environment variables definition in the .bashrc).

However, I cannot start the backup automatically. Can someone please push me in the right direction?

Thanks for participation
 
Last edited:
Hey,

if you want the env vars set in your .bashrc to be available in a cron job you have to source the file manually, like
13 22 1 * * "source <path_to_bashrc>; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1".
Or you can set the env vars directly without loading the whole .bashrc, like
13 22 1 * * "export VAR1=123; export VAR2=abc; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1".
Hope this helps, if you have any other questions just post here :D
 
Last edited:
It seems, i have a syntax problem. None of the following examples leads to a backup:

13 22 1 * * "source ~/.bashrc; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1"

13 22 1 * * "export PBSREPOSITORY="user@pbs@192.xxx.xxx.xxx:datastore"; export PBSPASSWORD="xxxx"; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1"
 
~ is relative to the current user, since cron does not run as your user you have to provide the absolute path to your .bashrc file. The second needs single quotes for the outer command, because currently all your " within the command are not escaped.
 
  • Like
Reactions: Meister Mopper
Sorry for my misunderstanding, i'm embarrassed.

It is in the .bashrc of root, so i tried

13 22 1 * * "source /root/.bashrc; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1"

even the single quotes did not lead to success.

13 22 1 * * 'export PBSREPOSITORY="user@pbs@192.xxx.xxx.xxx:datastore"; export PBSPASSWORD="xxxx"; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1'

Best regards and thanks for your patience
Thomas
 
I don't see any errors in syslog

Code:
May 31 11:00:01 pve CRON[28406]: (root) CMD ("source /root/.bashrc; proxmox-backup-client backup root.pxar:/")
May 31 11:00:01 pve CRON[28405]: pam_unix(cron:session): session closed for user root
May 31 11:00:01 pve postfix/pickup[7380]: 7E05581B87: uid=0 from=<root>
May 31 11:00:01 pve postfix/cleanup[28414]: 7E05581B87: message-id=<20210531090001.7E05581B87@xxx>
May 31 11:00:01 pve postfix/qmgr[1005]: 7E05581B87: from=<xxx@xxx>, size=666, nrcpt=1 (queue active)
May 31 11:00:01 pve postfix/smtp[28416]: 7E05581B87: to=<root@xxx>, orig_to=<root>, relay=xxx[xxx]:587, delay=0.5, delays=0.05/0.04/0.3/0.12, dsn=2.0.0, status=sent (250 2.0.0 Message accepted.)
May 31 11:00:01 pve postfix/qmgr[1005]: 7E05581B87: removed
 
Okay, got it. Thats how it works.

13 22 1 * * bash -c 'source /root/.bashrc; /usr/bin/proxmox-backup-client backup root.pxar:/ >/dev/null 2>&1'

Thank you for pushing me in the right direction :)

Best regards
Thomas
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!