LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-16-2011, 02:54 PM   #1
simmouk87
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Rep: Reputation: 0
Question Shell script to shutdown virtual machines. copy, and than start VM


Hi all,

Long time reader first time poster

I need to make my 1st ever script to backup VMware workstation VMs to a folder which is then backed up offsite.

Here is what I have so far (will be croned):

Code:
sudo vmrun -T ws  stop "/home/gareth/vmware/NagiosWeb/NagiosWeb.vmx" soft

sudo vmrun -T ws  stop "/home/gareth/vmware/UbuntuBackup/UbuntuBackup.vmx" soft

**copy or rsync to /home/gareth/vmware-backup/ dir**

sudo vmrun -T ws  start"/home/gareth/vmware/NagiosWeb/NagiosWeb.vmx"

sudo vmrun -T ws  start "/home/gareth/vmware/UbuntuBackup/UbuntuBackup.vmx"
The commands on their own work but I'm unclear on the below:

1. Just to confirm, I need to place the above in a file with #!/bin/bash at the top and make it executable
2. How do I know when the VMs have safely shut down so I can start the copy? I guess I can either a. wait a specified amount of time b. run some sort of if statement to confirm they are off
3. How do I use Rsync or cp to copy to the backup folder?
4. How will I know the copy is complete so that I can start the VMs again?


Any help would be greatly appreciated. Thanks
 
Old 03-18-2011, 10:48 AM   #2
MCD555
Member
 
Registered: May 2009
Location: Milan, Italy
Distribution: Ubuntu, Debian, Fedora, Oracle Linux
Posts: 109

Rep: Reputation: 10
Quote:
Originally Posted by simmouk87 View Post
Hi all,

Long time reader first time poster

I need to make my 1st ever script to backup VMware workstation VMs to a folder which is then backed up offsite.

Here is what I have so far (will be croned):

Code:
sudo vmrun -T ws  stop "/home/gareth/vmware/NagiosWeb/NagiosWeb.vmx" soft

sudo vmrun -T ws  stop "/home/gareth/vmware/UbuntuBackup/UbuntuBackup.vmx" soft

**copy or rsync to /home/gareth/vmware-backup/ dir**

sudo vmrun -T ws  start"/home/gareth/vmware/NagiosWeb/NagiosWeb.vmx"

sudo vmrun -T ws  start "/home/gareth/vmware/UbuntuBackup/UbuntuBackup.vmx"
The commands on their own work but I'm unclear on the below:

1. Just to confirm, I need to place the above in a file with #!/bin/bash at the top and make it executable
2. How do I know when the VMs have safely shut down so I can start the copy? I guess I can either a. wait a specified amount of time b. run some sort of if statement to confirm they are off
3. How do I use Rsync or cp to copy to the backup folder?
4. How will I know the copy is complete so that I can start the VMs again?


Any help would be greatly appreciated. Thanks
Hi,

1. yes, to make those lines into a shell script (bash) you should put the #!/bin/bash and make the file executable (chmod +x); but remeber, to make what you want you should always wait for a command response and manage that response....
also, in your script you can't use sudo in that way, or better, by default sudo prompt for a password.... but thera are ways to bypass this -> http://superuser.com/questions/25698...-in-plain-text(but not secure at all!?!)

2. look at the answer at point 1.... you need to manage the responses of the command issued

3. where do you wanna copy those files? Please be more specific.

4. again: look at the answer at point 1.... you need to manage the responses of the command issued


Hope this helps!
 
Old 03-18-2011, 11:33 AM   #3
simmouk87
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the reply.

1. sudo is not required actually so I don't need to worry about that but thanks for the link.
2. Not sure how that helps me? Please elaborate. I think I need to query the VM to see if it has shut down before starting the copy.
3. well if we just say the location is /my/backup/location ;-)
4. so how do I query the process to see if it has finished copying?

Thanks for your time.
 
Old 03-20-2011, 03:51 PM   #4
MCD555
Member
 
Registered: May 2009
Location: Milan, Italy
Distribution: Ubuntu, Debian, Fedora, Oracle Linux
Posts: 109

Rep: Reputation: 10
Quote:
Originally Posted by simmouk87 View Post
Thanks for the reply.

1. sudo is not required actually so I don't need to worry about that but thanks for the link.
2. Not sure how that helps me? Please elaborate. I think I need to query the VM to see if it has shut down before starting the copy.
3. well if we just say the location is /my/backup/location ;-)
4. so how do I query the process to see if it has finished copying?

Thanks for your time.
1. ok, so you'll run that script with root privileges, will you?
2. I mean, try the command and see what you get, or better, look for a manual (if exist) that give you a rc for your vm command
4&5. may this is easy: just concatenate the cp command to the start of you vm:
Code:
cp [path to your vm mage] /my/backup/location/[version]; [your start vm command]
But, excuse me for the question, have you think to take a simple snapshot of the vm without powered it of?

Code:
vmrun snapshot
After that you can check how many snapshot you have:

Code:
vmrun listSnapshots
and delete what you don't need

Code:
vmrun deleteSnapshot
Just a hint...sorry if it is out of your scopes!

Hope this helps!

Last edited by MCD555; 03-20-2011 at 03:57 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to create a shell script that would automatically backup and shutdown Daggaroth Programming 6 12-03-2010 11:19 AM
Shell script to ping machines info1686 Linux - General 5 08-03-2009 06:43 AM
shell script to shutdown computer twallstrom Programming 3 05-24-2008 08:46 PM
Shell Script to shutdown network computers? Brnzwngs Linux - Networking 6 09-11-2005 10:28 AM
Start-Up/Shutdown Script ptreves Linux - Newbie 1 09-15-2004 04:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration