how to automate proxmox backup client command

zerliob

New Member
Feb 27, 2021
11
1
3
68
Hi,
I want to automate the command below every day and keep savings of the last 14 days.
Is-it possible in PBS (prune?) and/or how to ?

proxmox-backup-client backup home.pxar:/home/ --repository root@pam@IP_PBS:backup

Thank you por your responses
François
 
Hi,

Normally you can do this by:
  1. Create cron job or systemd timer which is scheduled once every day (or how often you require it to be run) and executes the proxmox-backup-client command
  2. Create a prune schedule with "keep-days" set to 14 in the PBS Datastore settings - note this is then active for the whole datastore, if you want to use this retention setting for just this backup I'd add the prune command to the above cron job instead.
On what OS/Distribution would the command get executed?
 
Thank you for your response,
The command is executed on debian 10.
Do i have to make the two points or one or the other (cron and/or prune) ?
François
 
The first is for the backup itself the second is for the prune.

As you want both, you will have to do both.

The only choice you have to made is if you handle prune also in the cron job or if you configure it for the datastore on the PBS.

This crontab entry would do both, backup and prune daily at 01:00 o'clock in the morning:
Code:
0 1 * * * proxmox-backup-client backup home.pxar:/home/ --repository root@pam@IP_PBS:backup && proxmox-backup-client prune host/HOSTNAME --repository root@pam@IP_PBS:backup --keep-daily 14
 
  • Like
Reactions: lxiosjao
So, in my case, for saving /home on tuesday, wed, thu, fri and saturday at 3 o'clock, and keeping 14 savings, I put that file in /etc/cron.d :

0 3 * * tue,wed,thu,fri,sat root proxmox-backup-client backup home.pxar:/home/ --repository root@pam@192.168.0.46:sauvegardes && proxmox-backup-client prune host/se4fs --repository root@pam@192
.168.0.46:sauvegardes --keep-daily 14


Is that good ?
François
 
Hi,
don't forget to setup a garbage collection schedule as well for your datastore to actually free unused chuncks marked by the prune jobs.
 
Yes, GC schedule daily
I think I an have differents Prunes for host in cron and for m'y VMs. Am I right ?
 
Hi,

Normally, the backup should have taken place at 3 o'clock in the morning today, Tuesday. But it was not done!
When I run the command in a terminal, I have to enter the root password. With the cron, I cannot enter this password.
How do we fix this?
Thank you
 
OK
So I create /root/pbs.sh like that :

Bash:
#!/bin/bash

PBS_PASSWORD='mypassword'
PBS_FINGERPRINT='10:d3:7f:79:7e:e etcetera myfingerprint'
export PBS_PASSWORD
export PBS_FINGERPRINT

proxmox-backup-client login --repository root@pam@192.168.0.46:sauvegardes
proxmox-backup-client backup root.pxar:/ --repository root@pam@192.168.0.46:sauvegardes && proxmox-backup-client prune host/se4fs --repository root@pam@192.168.0.46:sauvegardes --keep-daily 14

pbs.sh runs very well

and then I add a file sauvhome in cron.d like that :
0 3 * * tue,wed,thu,fri,sat root /root/pbs.sh

I hope PBS will sent me a good new tomorrow morning (-:))

Thank you
 
  • Like
Reactions: kjgt256
Hi,
This morning, PBS sends me a mail : host OK, prune OK
IT WORKS !
Thanks a lot
François
 
you actually don't need the login line - that would only help for interactive use cases to store the ticket in a cache so you don't have to re-enter the password ;)
 
Aïe ! It does not work without the line login !
So I removed # before the line and it works again
Best regards
François
 
This thread saved me a lot of work, and I come here to thank you. I also had a similar credential problem with the Proxmox Backup Client running in a cron job. I followed the example in post #12, and it worked. I also found that I must have the login line for it to work. If I remove the login line, the credential problem will show up.
 
I'm curious - how do you troubleshoot this? I can run the proxmox-backup-client backup command manually and it works great, but when adding to cron, the scheduled task simply passes by.

cat /var/log/syslog | grep CRON says it ran at the scheduled time, but nothing actually happens. If I run the script manually with bash /root/pbs.sh I get errors before the backup runs:
Code:
root@pve:~# bash pbs.sh
pbs.sh: line 2: $'\r': command not found
': not a valid identifierPBS_PASSWORD
': not a valid identifierPBS_FINGERPRINT
pbs.sh: line 7: $'\r': command not found
Error: parameter verification errors

parameter 'repository': value does not match the regex pattern

Usage: proxmox-backup-client login [OPTIONS]
Optional parameters:

 --repository <string>
             Repository URL.

Starting backup: host/pve/2023-05-10T08:33:00Z
but the backup then starts and completes successfully.

I'm not sure how to troubleshoot further. My pbs.sh file is the same as in post #12 (-pruning), but I'll paste below.

Bash:
#!/bin/bash

PBS_PASSWORD='<mypass>'
PBS_FINGERPRINT='9c:39:f8:dd:c5...'
export PBS_PASSWORD
export PBS_FINGERPRINT

proxmox-backup-client login --repository root@pam@192.168.1.214:pbs-backups
proxmox-backup-client backup root.pxar:/ --repository root@pam@192.168.1.214:pbs-backups
 
sounds like your script file is broken - did you maybe edit it on Windows and that messed up the file?
 

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!