Giter VIP home page Giter VIP logo

virtualbox_export_script's Introduction

Explanation for the VBoxManage python script

This also includes a version that once completed, would allow you to make a number selection along with being able to select all the vms and loop through the backup script until all the vms have completed a backup. That version is TestCode. I do not have the knowledge to make this work, so I have to use this. Also includes the previous version of this, which sets the variables in the fuctions as global. The VBoxManage version has fixed this.

Previous_Version

VBoxManage

TestCode

Requirements

  • Needed to run commands from cmd
    • import subprocess
    • import os
  • Needed to get the date for later folder creation
    • from datetime import date
  • Get the current date in DDMonth(Abrev)YYYY
    • d4 = date.today().strftime("%d%b%Y")
    • d4 stores the current date for later

Gettting the values

  • Define the function
    • def get_values():
  • Add tasks to the function
    • Call VBoxManage and list the vms
      • subprocess.run(["VBoxManage.exe", "list", "vms"])
    • Ask which vm to Backup
      • get_values.VMName = input("Which VM do you want to backup? ")
    • List the drives and ask which one to use
      • subprocess.run(["wmic", "LOGICALDISK", "LIST", "BRIEF"])
      • get_values.DriveDest = input("Letter of drive you want to store backup on: ")
    • Bring it al together to make the VM destination string
      • get_values.VMDest = str(get_values.DriveDest) + ":\VM Backup\\" + str(d4) + str("\\") + str(get_values.VM_BAK_NAME)

Define the backup function

  • Define the function
    • def VM_BAK():
  • Add tasks to the function
    • subprocess.run(["VBoxManage.exe", "export", str(get_values.VMName), "--options", "iso", "--ovf10", "--output", str(get_values.VMDest)])

Define the make directory function

  • Define the function
    • def make_directory():
  • Add tasks to the function
    • Print a message saying the directory does not exist
      • print("Directory does not exist, creating now")
    • Create the directory
      • os.mkdir(str(get_values.DriveDest) + ":\VM Backup\\" + str(d4))

Change to the correct directory

  • VBoxManage directory
    • Change to the VirtualBox directory
      • os.chdir("C:\Program Files\Oracle\VirtualBox")

Invoke the get_values function

  • Invoke the get_values function
    • get_values

Test if the backup directory exists or not

  • Define the path to check
    • path_test = str(get_values.DriveDest) + ":\VM Backup\\" + str(d4)
  • Return a true or false value based on if the directory exists or not
    • ispath = os.path.isdir(path_test)

Invoke the deciding IF statement

  • This statement decides what to do based on if the directory exists
    • If directory exists, starts backup
      • if ispath == True: print("Directory already exists, starting backup") VM_BAK()
    • If directory does not exist, creates it and starts backup
      • elif ispath == False: make_directory() VM_BAK() else: end

virtualbox_export_script's People

Contributors

theman1616 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.