Backup your VMWare Machine to a Backup Server using CronJob
Running a script to backup your VMWare machine. If you are running a server as a Virtual Machine and you are using VMWare to do this, you can
have this VMware Virtual Machine completely backed up in a periodic basis, and here is how
Assumptions
You are going to make your backup in another PC not on the same the Virtual
Machine is running.
Tasks
1. Make possible to log into remote machines using no password
2. Create the script to rotate your backup files in the destination server
3. Create the cron file
1. Make possible to log into remote machines using no password
This is needed because when we copy the files from the server running VMWare to the
backup server, we will not be able to enter the password, we will scp which will copy the files
over a ssh connection, so we will need openssh server installed on the backup server
You can follow this instructions to have this done, you have to able to log from the server
running your Virtual Machine to the backup Server
2. Create the script to rotate your backup Files in the destination server
-- First go to the backup server and create two folders in you home directory, these folders
will be for the backup files.
|
mkdir $HOME/backup mkdir $HOME/vmachine |
-- Now create the script $HOME/backup/archivo.sh and make it executable with:
chmod +x $HOME/backup/archivo.sh
|
rm /home/user/backup/backup1.tar.gz |
3. Create the cron file
-- The cron file should be placed on the /etc/cron.d/ directory of the Server where the
virtual machine is hosted and should look like this:
|
50 12 * * 1,3,5 root ssh root@ip.of.the.backup.server $HOME/backup/archivo.sh 28 13 * * 1,3,5 root ssh ip.of.the.virtal.machine poweroff 29 13 * * 1,3,5 root scp /var/lib/vmware/Virtual\ Machines/virtualmachine/* root@ip.of.the.backup.server:$HOME/backup/ 34 13 * * 1,3,5 root vmrun start /var/lib/vmware/Virtual\ Machines/virtualmachine/virtualmachine.vmx |
1. At 12:50 on monday, wednesday and Friday, execute on the backup server the rotate
script
2. At 13:28 on monday, wednesday and friday, turns off the Virtual Machine
3. At 13:29 on monday, wednesday and friday, copy the Virtual machine files from the host
server to the backup server
4. At 13:34 on monday, wednesday and Friday turns the Virtual machine on.
if you are not using "root" what i recomend you, also the file "virtualmachine.vmx" should be the
name of your virtualmachine.
Trackback URL for this post:
If you like this article, subscribe to our full rss
Please post your question in our forum and use comments only to leave your comments about the article, thanks.













This is just daft - What
This is just daft - What happens if step 2 takes longer than 1 minute? or step 3 takes longer than 5 minutes?
Steps 2,3,4 should all be done in one shell script to minimize downtime and decrease the chances of something failing.
WARNING TO ANYONE who follows this guide:
THIS BACKUP METHOD IS NOT RELIABLE.
Merge Steps 2,3,4 into one shell file (and hence, one cronjob) and space out the rotater and backup times. There is not need to rotate just before the backup. Do it 12 hours or whatever in advance.
...
Thank you, good idea, I
Thank you, good idea, I agree that if you merge step 3 and 4, in one shell script, step four will not start 'till step three is finished, but I do not think the same thing is going to happen with step two, 'cause the system is going to send the poweroff signal, and as far as I know it will not going to receive any signal once the VMware machine is off, so step 3 is going to start inmediately after step 2.
I also agree with the rotate idea, thanks for improving the method.
Guillermo Garron
Post new comment