Backup Proxmox Virtual Machine to Remote Server using Python script

import subprocess
import sys

def initiateBackup(vmID):

    # Lets build command to execute

    command = []
    command.append("vzdump")
    command.append(vmID)

    # Executing the command

    result = subprocess.call(command)

    if(result==0):
        return "OK"
    else:
        print("Backup was not successfull.")
        sys.exit()

def getPath(vmID):

    import os

    for file in os.listdir("/var/lib/vz/dump"):

        if file.endswith(".vma") and (file.find("vzdump-qemu-"+vmID)>-1):

            return "/var/lib/vz/dump/"+file

def sendFileViaSCP(ipAddress,srcFile,destination):

    print("#####################################################")
    print("                  Sending via scp                    ")
    print("#####################################################")

    # Lets build command to execute

    command = []
    command.append("scp")
    command.append(srcFile)
    command.append("root"+"@"+ipAddress+":"+destination)


    # Executing the command

    result = subprocess.call(command)

    if (result == 0):
        print("#####################################################")
        print("               File Sent via scp                     ")
        print("#####################################################")
        return "OK"
    else:
        print("Backup File Not Sent")
        sys.exit()

def Main():
    
    initiateBackup("101")
    src = getPath("101")

    ipAddress = "94.176.233.214"
    username = "root"
    destination = "/root"

    sendFileViaSCP(ipAddress,src,destination)


Source: https://cyberpersons.com/2017/05/31/use-python-to-automatically-backup-proxmox-virutal-machine-to-remote-server/


Komentar

Postingan populer dari blog ini

Cara memahami dan menghafal model OSI dengan analogi

Pembahasan IT Network Systems Administration Module A DNS (Forward Zone, Reverse Zone, CNAME, MX, Split View)

Table of Contents