So I was less than thrilled with the method of using ftp to pull the backups. Mostly because it had a ton of extra configuration, but more importantly the implementation of FTP was less then stellar. I have my K1000 in my DMZ and I would have had to open a lot of ports just to allow data transfer. On top of that there was no method of retaining files.

My solution was to write a power shell script that I could schedule using windows task scheduler and have the script clean up my files I no longer needed. The script copies the files from the K1000 to a location on my NAS where I use commvault to back it up at the file level to disk and tape.

This method relies on using the direct http links and using powershell to retrieve the files from those urls.

The script has two components: a .BAT file which calls the PS1 file. This is because you cannot call a powershell script directly from the task schedule so I just the BAT file to load powershell and execute the script.

The script is heavily commented and you should only need to edit files in the Variable - EDIT section. Also to note, there are two back up files, one for the Database which is fairly small and the Files which are fairly large if you are using a lot of deployments etc.

If you have any questions please feel free to comment and I will do my best to help you out.

1. - The Script: K1000Backup.ps1 - Copy this into a txt file and save it as a .ps1 in whichever location you use. Copy and paste into notepad before editing etc. Formatting does not display properly on the blog but it shows up properly in notepad.

#####################################################
#This script will allow you to set a scheduled      #
#task and automatically backup your k1000           #
#please feel free to distribute but just include    #
#the copyright info and url to the original forum   #
#post on itninja,com                                #
#        Copyright 2012 - Andrew Raia               #
#####################################################

###########################
# Variables - EDIT        #
###########################

# This is the FQDN of your kbox
$myKbox = "kbox.domain.com"

# This is the place you wish to store your backups. Use a UNC if you plan on running when no user is logged on.
# Also Make sure account running this script has permissions to this location
$myBackupPath = "UNC Path"

# This defines how many days I want to keep on disk of each backup
$myFilesRetention = "7"
$myDBRetention = "30"

# Set overwrite (set to "enabled" if you want to overwrite backups with the same name, otherwise "disabled")
$myOverwriteOption = "disabled"

##########################################
# Execute Backup Retention - DO NOT EDIT #
##########################################

# Create useable var for the path to all file backups
$FileRetentionPath = "$myBackupPath" + "*.tgz"

# Create useable var for the path to all DB backups
$DBRetentionPath = "$myBackupPath" + "*.gz"

# Removes backup files in the backup path based on the number of days specified in the retention variable
echo "Please be patient while your backup directory is being cleaned..."

# File Retention
echo "Files older than $myFilesRetention day(s) are being removed"
Get-ChildItem "$FileRetentionPath" -recurse | where {$_.Lastwritetime -lt (date).adddays(-$myFilesRetention)} | Remove-Item -Force

# DB Retention
echo "Files older than $myDBRetention day(s) are being removed"
Get-ChildItem "$DBRetentionPath" -recurse | where {$_.Lastwritetime -lt (date).adddays(-$myDBRetention)} | Remove-Item -Force

###########################
# Variables - DO NOT EDIT #
###########################

# This gets the current date and formats it the way the kbox does in the backup file
$myDate = Get-Date -format "yyyyMMdd"

# This is the url for the database files
$urldb = "http://$myKbox/common/download_file.php?FILENAME=/kbackup/$myDate" + "_k1_dbdata.gz"

# This is the path that it will store your backups in
$pathdb = "$myBackupPath" + "$myDate" + "_k1_dbdata.gz"

# This is the url for the Files backup
$urlfile = "http://$myKbox/common/download_file.php?FILENAME=/kbackup/$myDate" + "_kbox_file.tgz"

# This is the path that it will store your files backup in
$pathfile = "$myBackupPath" + "$myDate" + "_kbox_file.tgz"

$myDBExist = Test-Path $pathdb
$myFileExist = Test-Path $pathfile

###################################
# Execute DB Backup - DO NOT EDIT #
###################################

echo "Please be patient while your K1000 files are being copied...."

# Check to see if the DB backup already exists, if not go ahead and copy it
if ($myDBExist -eq $False) {
echo "DB Backup is being copied"
$clientDB = new-object System.Net.WebClient
$clientDB.DownloadFile( $urldb, $pathdb)
}
# If the database already exists and overwrite is enabled then copy overwrite the existing file
elseif ($myDBExist -eq $True -And $myOverwriteOption -eq "enabled"){
echo "DB Backup already exists but is being overwritten because overwrite is enabled"
$clientDB = new-object System.Net.WebClient
$clientDB.DownloadFile( $urldb, $pathdb)
}
# If the database backup already exists and overwrite is disabled, then do nothing
else {
echo "DB Backup is being skipped because overwite is disabled and the file already exists"
}

#####################################
# Execute File Backup - DO NOT EDIT #
#####################################

# Check to see if the DB backup already exists, if not go ahead and copy it
if ($myFileExist -eq $False) {
echo "File Backup is being copied"
$clientfile = new-object System.Net.WebClient
$clientfile.DownloadFile( $urlfile, $pathfile)
}
# If the database already exists and overwrite is enabled then copy overwrite the existing file
elseif ($myFileExist -eq $True -And $myOverwriteOption -eq "enabled"){
echo "File Backup already exists but is being overwritten because overwrite is enabled"
$clientfile = new-object System.Net.WebClient
$clientfile.DownloadFile( $urlfile, $pathfile)
}
# If the database backup already exists and overwrite is disabled, then do nothing
else {
echo "File Backup is being skipped because overwite is disabled and the file already exists"
}


##############################
# Debugging                  #
##############################

# Uncomment the following to verify your variables. You may also want to comment out execute backup sections above to skip copying.
# echo "DB URL: $urldb"
# echo "DB Path: $pathdb"
# echo "File URL: $urlfile"
# echo "File Path: $pathfile"
# echo "DB Backup Already Exists: $myDBExist"
# echo "File Backup Already Exists: $myFileExist"
# echo "FileRetentionPath: $FileRetentionPath"
# echo "DB Retention Path: $DBRetentionPath"

 

2. The .BAT file - K1000Backup .bat - copy this into a txt file and save it as a .bat in the same location as your powershell file. Make sure the location in this bat file points to the path of your powershell file as well as the path for the log file.

@echo off
PowerShell.exe "C:\Scripts\k1000backup\k1000Backup.ps1" >c:\Scripts\K1000backup\log.txt

3. Schedule a task to run the .BAT file according to your desired schedule. I set mine to run daily, and set it to run hidden even when a user is not logged on.