Post

6 followers
3
Avatar

Backup/export all Jams folders, jobs, and variables to xml JAMS >7.x

 
 

This script export all jams folders, jobs, and variables to same structure as your folder definitions.

Xml files has prefix Job_, and Variable_.  It creates a logfile if you need it.

For  JAMS > 7.x

<#

.SYNOPSIS

The purpose of this script is to backup all jobs, setups and variables to xml files for a long term archive.

JAMS version > 7.x

.DESCRIPTION

.NOTES

File Name : BackupJamsToXml.ps1

Tags : JAMS, Backup, XML

Version: 1.1.0 - 2018-08-30

Author: Niclas Hultberg

#>

#Import the JAMS Module

Import-Module JAMS

If (!(Test-Path JD:))

{

New-PSDrive -Name JD JAMS localhost

}

else { }

#Export variables to change

$DateFormat = "yyyyMMdd_Hmm"

$ExportFolder = "D:\cron\JAMS\Export\"

$ActiveLog = "0" #Activate log set to 1

##########################################################################

#JAMS do not change

$LogFolder = $ExportFolder + "\@Logg\"

$Logfile = "JamsExport_$(get-date -f $DateFormat).txt"

$Log = $LogFolder + $Logfile

#Check if log folder exists

If(!(test-path $LogFolder))

{

New-Item -ItemType Directory -Force -Path $LogFolder

}

else { }

#####

#Statistics

$JamsFolderStat = Get-ChildItem JD:\* -objecttype Folder -IgnorePredefined -Recurse

$JamsJobStat = Get-ChildItem JD:\* -objecttype Job -IgnorePredefined -Recurse

$JamsVariableStat = Get-ChildItem JD:\* -objecttype Variable -IgnorePredefined -Recurse

IF($ActiveLog= "1") {

$JamsFolderStat.Count | Out-File $Log -Append

$JamsJobStat.count | Out-File $Log -Append

$JamsVariableStat.count | Out-File $Log -Append

}

#####

# Function to extract all jobs, setups and variables

Function JamsGetAll ($JamsFolder){

ForEach ($JamsFolders in $JamsFolder){

$Exportpath = $ExportFolder + $JamsFolders

#create folders

If(!(test-path $Exportpath))

{

New-Item -ItemType Directory -Force -Path $Exportpath

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);Directory; $Exportpath was created." | Out-File $Log -Append }

}

else { }

#Exporting jobs, setups and variables

$job = Get-ChildItem JD:\$JamsFolders\* -objecttype Job -IgnorePredefined #-Recurse

ForEach ($jobs in $job)

{

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);Job ;$Exportpath\Job_$($jobs.Name).xml " | Out-File $Log -Append }

Export-JAMSXml "$Exportpath\Job_$($jobs.Name).xml" $jobs

}

$variable = Get-ChildItem JD:\$JamsFolders\* -objecttype variable -IgnorePredefined #-Recurse

ForEach ($variables in $variable)

{

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);Varable ;$Exportpath\Variable_$($variables.Name).xml " | Out-File $Log -Append }

Export-JAMSXml "$Exportpath\Variable_$($variables.Name).xml" $variables

}

}

}

#Export and create folders on level one

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);****Start exporting level one.****" | Out-File $Log -Append }

$JamsRootFolder = Get-ChildItem JD:\* -objecttype Folder -IgnorePredefined #-Recurse

#Call function

JamsGetAll $JamsRootFolder.Name

#Export and create folders on level two

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);****Start exporting level two.****" | Out-File $Log -Append }

$JamsRootFolderTwo = @()

ForEach ($level in $JamsRootFolder.Name){

Get-ChildItem JD:\$level\* -objecttype Folder -IgnorePredefined | ForEach-Object {$JamsRootFolderTwo += $level +"\"+ $_.Name}

}

JamsGetAll $JamsRootFolderTwo

#Export and create folders on level three

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);****Start exporting level three.****" | Out-File $Log -Append }

$JamsRootFolderThree = @()

ForEach ($level in $JamsRootFolderTwo){

Get-ChildItem JD:\$level\* -objecttype Folder -IgnorePredefined | ForEach-Object {$JamsRootFolderThree += $level +"\"+ $_.Name}

}

JamsGetAll $JamsRootFolderThree

#Export and create folders on level four

IF($ActiveLog= "1") {"$(get-date -F $DateFormat);****Start exporting level four.****" | Out-File $Log -Append }

$JamsRootFolderFour = @()

ForEach ($level in $JamsRootFolderThree){

Get-ChildItem JD:\$level\* -objecttype Folder -IgnorePredefined | ForEach-Object {$JamsRootFolderFour += $level +"\"+ $_.Name}

}

JamsGetAll $JamsRootFolderFour

Prong Development

Please sign in to leave a comment.

4 comments

0
Avatar

Thanks, I tested it (Backup and restore), it works well.

 

Alexis Dominguez 0 votes
0
Avatar

When you import do you have problems with spacing in the description?

Logan Probst 0 votes
0
Avatar

hello, im new to using the jams powershell. i got the backup script to work, how do i create the import to succesfully import?

Henry Offiah 0 votes
0
Avatar

Hi I import using the GUI in JAMS, have no need to restore all. We use it to easy restore object that we removed. I don`t like to have a lot of objects that are disabled in the GUI.

Prong Development 0 votes