Hello,
I am planning to backup my linux laptop via proxmox-backup-client. I just wrote this little script to automate the process:
My daily computer being a laptop, I don't have a fixed time to backup (I close it when I don't use it). So my idea is to run this script via crontab (every hour for example) and have the script check that:
What do you think about this approach?
I still have a few questions though:
Thanks for your advises!
I am planning to backup my linux laptop via proxmox-backup-client. I just wrote this little script to automate the process:
Bash:
#!/bin/bash
### Depedencies ########################################
# jq (to parse the json output of snapshots) #
# PBS_PASSWORD must be exported in: #
# ~/.bashrc (to be run by user) #
# ~/.bash_profile (to be run by cron with "bash -l") #
########################################################
### Settings ###################
_pbs_ip_address="192.168.x.x" #
_pbs_user="user@pbs" #
_pbs_datastore="backups" #
################################
# I check that I am not connected to a metered network
# (See https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMMetered)
_metered_value=$(busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered)
if [ "$_metered_value" == "u 4" ] || [ "$_metered_value" == "u 2" ]; then
echo "- The bandwidth on this network is probably not metered"
# I check that I can ping the server
ping $_pbs_ip_address -c 1 > /dev/null 2>&1
if [ $? == 0 ]; then
echo "- The Proxmox Backup Server is reachable"
_epoch_last_backup=$(proxmox-backup-client snapshots --output-format json --repository $_pbs_user@$_pbs_ip_address:$_pbs_datastore | jq '[ .[]."backup-time" ] | max')
_seconds_elapsed_since_last_backup=$(($(date +%s)-$_epoch_last_backup))
echo "- The last backup was received on "$(date -d @$_epoch_last_backup)" ("$_seconds_elapsed_since_last_backup" seconds ago)"
# I run the backup if the last one is more than 24H old (86400 seconds)
if [ $_seconds_elapsed_since_last_backup -gt 86400 ]; then
echo "- I start the backup"
proxmox-backup-client backup root.pxar:/ --repository $_pbs_user@$_pbs_ip_address:$_pbs_datastore
fi
fi
fi
My daily computer being a laptop, I don't have a fixed time to backup (I close it when I don't use it). So my idea is to run this script via crontab (every hour for example) and have the script check that:
- I am NOT connected to a metered network (such as my mobile phone acting as a hotspot for example)
- I can ping the server. If I am at a hotel and forgot to connect to my VPN, I don't want to send my credentials for nothing (I am not sure the communication with PBS is encrypted?)
- The latest backup is at least 24 hours old
What do you think about this approach?
I still have a few questions though:
- unprivilegied users can't backup some root files. So I am planning to run it via root's crontab. Any better idea?
- On PBS side, I guess I just need the "read" and "backup" permissions (to get the latest backup time, and to backup). So I had to grant 2 separate permissions (1x for DatastoreReader + 1x for DatastoreBackup) in order to limit the permissions to the maximum. Is there a better way?
- If possible, I would like to postpone my backup if another client is already busy backing up on my PBS (to limit the pressure on the network). Is it possible to check if another client is busy (possibly without granting too much permissions)?
Thanks for your advises!
Last edited: