Home VMwareAutomation How to Schedule Automatic Backup for VMware Cloud Director

How to Schedule Automatic Backup for VMware Cloud Director

by Mohamed Imthiyaz
Automatic Backup VCD

In this blog post, we’ll explore how to automate the backup process for VMware Cloud Director, streamlining the workflow and enabling a retention policy.

There’s no official document to automate the VCD backup. I have written a bash script that will automate the VCD backup process and retention.

I am on VCD 10.5

Please note this script has to be on root cronjob usage on all Cells.
The script verifies whether the current cell is designated as primary or standby. If it’s identified as the primary cell, it proceeds to execute the backup process. Following the backup operation, it scans for any backups older than 30 days and removes them, providing a list of the deleted backups. If the cell is not designated as the primary, the script takes no further action.


# Directory where backups are stored

# Function to check and delete the backups which are older than 30 days
remove_old_backups() {
  # Find files older than 30 days
  older_backups=$(find "$vcd_backup" -type f -mtime +30)

  if [ -n "$older_backups" ]; then
    # If older backups are found, delete them
    echo "Deleting older backups:"
    echo "$older_backups" | xargs -t rm -f
    # If no older backups are found, print a message
    echo "No backups older than 30 days found."

# Check if the current node is the Primary VCD Cell
if sudo -i -u postgres repmgr node check --role | grep -q primary; then
  echo "Running Backup Job"
  # Execute the backup script
  # Call the function to remove old backups
  echo "This is not the Primary cell"

How to Use the script

Clone the Repository: Clone the repository containing the script to your local machine.

Edit Script (Optional): If needed, modify the script to specify the correct backup directory or adjust any other settings according to your environment.

Set Execute Permissions: Ensure the script has execute permissions. If not, run:

chmod +x vcd_backup_script.sh

Test the Script: Before adding it to a cron job, test the script to ensure it functions as expected:

Run the script


Add to Cron Job: To schedule the script to run automatically at specific intervals, add it to the cron job. For example, to run the script daily, use:

0 0 * * * /path/to/vcd_backup_script.sh > /dev/null 2>&1

Script explanation is on my github repo.

Hope this helps.

You may also like

Leave a Comment