Showing posts with label backup. Show all posts
Showing posts with label backup. Show all posts

17 August, 2010

Xen Server Automatic Host backup script using batch

Hi,

You can never be too carefull, here is an automated backup script for xen server host.
Be careful, it can reach to 1G... (Mine did).

as always you will need a list file with the names of the xen hosts (case sensitive), name it host_list.txt.
and the following: (this will keep 2 versions, you can remove those lines if you want)
replace [] with your data.
====================================
for /f %%A in (host_list.txt) do (
del "D:\Backup\XenServer\OLD_%%A_Backup.bak" /q
ren D:\Backup\XenServer\%%A_Backup.bak Old_%%A_Backup.bak
"C:\Program Files\Citrix\XenCenter\xe.exe" -s [server ip] -u [user] -pw [password] host-backup host=%%A file-name=D:\Backup\XenServer\%%A_Backup.bak
)
====================================

08 July, 2010

Live Xen Backup using a batch job

Hi,

I like batch jobs more than VBS, I'm old fashion. :)
I wrote a script to backup Xen Server guests machines using batch.

The script will clean old snapshots with a single SR, then will try to create a snapshot with  quiesce (using VSS) and if not successful, will do a regular backup.

It contains 4 files:
1. VM_List.exe - the list of the vm names you want to backup (one per line)
2. Step1.cmd - the file you need to run, will enumerate the list of machines to backup
3. Step2.cmd - a command to delete all the old snapshots (more complicated that it sounds)
4. Step3.cmd - the actual backup script

and now the content of the files (VM_List.exe I believe you can create yourself):
Replace [] with your data.

Step1.cmd:
=====================================
echo off
set server=[pool master ip]
set user=root
set password=[password]
call XenBackup-Snapshots-step2.cmd > log_snap.txt
for /f %%A in (vm_list.txt) do (XenBackup-Snapshots-step3.cmd %%A >>log_snap.txt)
=====================================

Step2.cmd: (I assume you have 1 SR, if you have more just replicate this script per SR)
=====================================
echo === deleting old snapshot ===
echo Start at:
echo %date% - %time%
:start
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% vdi-list is-a-snapshot=true sr-uuid=[sr-uuid] --minimal > vdi.txt
for /f "tokens=1 delims=," %%G in (vdi.txt) do (
if [%%G] EQU [] goto end
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% vdi-destroy uuid=%%G
echo.
goto start
)
:end
=====================================

Step3.cmd:
=====================================
echo off
setLocal EnableDELAYedExpansion
title ***** Working on %1 *****
echo ***** Start working on %1 *****
echo.
echo === Start Backup for %1 ===
echo.
echo Start at:
echo %date% - %time%
set vm_uuid=
set template_uuid=
"C:\Program Files\Citrix\XenCenter\xe.exe" -s 192.168.120.10 -u %user% -pw %Password% vm-list name-label="%1" --minimal > vm_uuid.txt
set /p vm_uuid=

set snapshot-type=vm-snapshot-with-quiesce
:snapshot
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% %snapshot-type% new-name-label=backup uuid=%vm_uuid% > template_uuid.txt
set /p template_uuid=

set C=-
set N=
:loop
if !template_uuid:~0^,1! equ !C! (
set /a N+=1
)
if "!template_uuid:~1!" neq "" (
set template_uuid=!template_uuid:~1!
goto :loop
)
if !N! NEQ 4 do (
if %snapshot-type%==vm-snapshot goto no_snap else
set snapshot-type=vm-snapshot
goto snapshot
)

C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% template-export template-uuid=%template_uuid% filename=d:\VM_Backup\%1.xva
echo.

:no_snap
echo NO SNAPSHOT !!!
:emd
echo.
echo %date% - %time%
echo ***** End working on %1 *****
echo.

=====================================

20 May, 2010

Central Fortigate Backup script

Hi,

I have several sites with fortigate as the firewall and a lot of on the fly changes on them, I wrote a script for automatic backup of the fortigates, it uses the following tools:
- PLINK
- 7zip

You need to prepare a FTP site to backup to, I created the site on the machine that runs the backup and this way I can zip it up after the backup completes.

just run it once a day and it will keep history for each day.
change each [] field with your values.


===========================================================
echo off
set user=[username]

rd D:\Backup\Fortigate\Temp /s /q
md D:\Backup\Fortigate\Temp

:1st
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=2nd
goto start_bk

:2nd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=3rd
goto start_bk

:3rd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=7zip
goto start_bk

:start_bk
echo === Backing up %hostName% at %hostIP% ===
echo execute backup config ftp /fortigate/Temp/%hostname%_%hostIP%.conf [traget ftp ip] [ftp user] [ftp password] > Command.txt
plink -ssh %hostIP% -l %user% -pw %pass% -m D:\Work\Fortigates_Backup\Command.txt
del command.txt /q
echo.
goto %next%

:7zip
Set MONTH=%DATE:~4,2%
Set DAY=%DATE:~7,2%
Set YEAR=%DATE:~10,4%
7z.exe a -r "D:\Backup\Fortigate\FG_%DAY%-%MONTH%-%YEAR%.zip" D:\Backup\Fortigate\Temp\*.*

:end

====================================================================

have fun.

11 May, 2010

Delete all snapshots in a SR (XenServer)

Hi,

Wrote a little script to centrally delete all snapshots from a SR on XenServer.
I noticed that although you delete a snapshot an entry still remains on the SR.
Since I have 1 main SR I wrote a script to delete all of them before the backup process begins (later when it will be ready I'll post it).

================================================
echo === deleting old snapshot ===
echo Start at:
echo %date% - %time%
:start
C:\Progra~1\Citrix\XenCenter\xe.exe -s [Pool Master / Server IP] -u [user] -pw [password] vdi-list is-a-snapshot=true sr-uuid=[sr uuid] --minimal > vdi.txt
for /f "tokens=1 delims=," %%G in (vdi.txt) do (
if [%%G] EQU [] goto end
C:\Progra~1\Citrix\XenCenter\xe.exe -s [Pool Master / Server IP] -u [user] -pw [password] vdi-destroy uuid=%%G
echo.
goto start
)

:end
=================================================

and it works great...

14 September, 2009

Automatic backup of XenServer vm with vm-export

Hi,

I needed to schedule a weekly backup of my VM's in my XenServer.
When I googled it I found a script written by Jeff Riechers, this script was good but did not help me because I did not have enough storage to take a snapshot to each VM.
I had to tweak it and I improved the method of retrieving the uuid (no more temp files...).

The final script reads from a file (named serverlist.txt) the vm name and the host on it resides. This is because I noticed that when I shut down the VM it gets a deferent home server, so I forced it to start on a specific host.

Just schedule it with cscript and your good to go.

Link to the script