i want to regularly transfer proxmox backup files on an external hard disk. how can I automatize the copying of the backup file such that every day at 4 am in order to just copy files that are not already available in the destination? provide the answer in markup formatting.
You can automate the backup transfer process using a cron job that runs every day at 4 AM. This cron job can use the rsync command to copy the backup files from the Proxmox server to the external hard disk, ensuring that only new or modified files are transferred.
Here's how you can set it up:
Ensure that your external hard disk is mounted on a specific directory, for example /mnt/external_backup. You can add an entry in your /etc/fstab to automatically mount the external hard drive on boot.
bash
Copy code
UUID=<your_disk_uuid> /mnt/external_backup ext4 defaults 0 2
Replace <your_disk_uuid> with the actual UUID of your external hard drive, which you can find by running:
bash
Copy code
lsblk -f
To create the cron job that will run every day at 4 AM, follow these steps:
Open the cron file for editing:
bash
Copy code
crontab -e
Add the following line to schedule the backup task at 4 AM every day:
bash
Copy code
0 4 * * * rsync -av --ignore-existing /path/to/proxmox/backups/ /mnt/external_backup/
rsync Command:-a: Archive mode, which preserves permissions, times, symbolic links, etc.-v: Verbose mode, so you can see what is being transferred.--ignore-existing: This option ensures that rsync will not overwrite files that already exist on the external hard drive. Only new or modified files will be copied./path/to/proxmox/backups/: Replace this with the actual path to your Proxmox backup files./mnt/external_backup/: Replace this with the path where your external hard drive is mounted.bash
Copy code
0 4 * * * rsync -av --ignore-existing /var/lib/vz/dump/ /mnt/external_backup/
This cron job will run at 4 AM every day, copying only new or modified backup files from /var/lib/vz/dump/ (default Proxmox backup directory) to /mnt/external_backup/ (the external hard disk).
After adding the cron job, you can verify that it's been added by running:
bash
Copy code
crontab -l
This will list all the active cron jobs for the current user.
With this setup, the backup files from Proxmox will automatically be copied to your external hard disk every day at 4 AM, and only files that are not already present on the destination will be transferred. This ensures efficient use of time and storage space.