compress all virtual machines

Discussion in 'General Questions' started by urza311, Dec 6, 2012.

  1. urza311

    urza311 Bit poster

    Messages:
    3
    I don't believe this is currently an option, but it'd be a nice one to add in the future. On some of my Parallels installs, I have multiple virtual clients created. Periodically, I shut them all down and -- one by one -- run through the "reclaim disk space" command to get space back. One system in particular I have runs six different virtual Windows systems, and once a month I compress all the systems -- it nets me back several gigabytes.

    One small complaint -- I have to do each compression individually. I'd love it if there was a "compress all virtual machines" command you could run (while all systems were shut down, naturally). Then I could go do something else for a while and come back to find them all crunched down.

    Any chance there's some secret key combo that does this? Or that it can be added as to the wish list for a future release? Thanks.
     
  2. Stuw

    Stuw Parallels Developers

    Messages:
    296
    Hi

    Try following script...

    % cat ./compact.sh
    #!/bin/bash

    prlctl list -a | sed -n 's/\([0-9A-Z]*\-\)/\1/p' | grep -v stopped > /dev/null 2>&1
    if [[ $? == 0 ]]; then
    echo "There is not stopped VMs. Please stop all VMs to perform compression"
    exit 1
    fi


    function compact_vm() {
    local vm="$1"

    local vm_name=$(prlctl list --info "$vm" | grep Name | sed -n 's/^Name: \([\S]*\)*/\1/p')
    echo -e "\nCompacting \"$vm_name\" ($vm)"

    IFS='
    '
    for hdd in $(prlctl list --info "$vm" | grep hdd | sed -n "s/.*image='\([0-9A-Za-z -./]*\)'.*/\1/p"); do
    echo -e "\tProcessing $hdd"
    prl_disk_tool compact --hdd "$hdd"
    done
    }

    for vm in $(prlctl list -a | sed -n 's/\([0-9A-Z]*\-\)/\1/p' | grep stopped | awk '{print $1}'); do
    compact_vm "$vm"
    done

    p.s. don't forget set executable permissions for script file:
    chmod a+x ./compact.sh
     

Share This Page