@george1421 said in Copy Cloud Storage of /images to Remote Servers Globally:
@JJ-Fullmer do you know if there is an API for exporting image definitions from fog?
https://forums.fogproject.org/topic/12026/powershell-api-module
The other option might be to write some mysql code to export the image def table on the root fog server then to import it on the remote fog server end. This could be added to your cron job as part of the image movements.
As long as the receving end fog server doesn’t create its own images the export and import with mysql should be pretty clean. If the receiving end fog server also created images then there is the problem of duplicate image IDs in the database.
Sorry I just saw this
100% you can get image definitions from the api and you could then store them in json files. It would be a lot simpler, easier and safer than direct database calls in my opinion and it handles the whole column sql stuff.
Here’s a quick sample of what you might do
On the source server with the original image install and configure the fogApi powershell module.
Open up a powershell console
#if you're new to powershell you may need this
Set-executionpolicy RemoteSigned;
#install and import the module
Install-Module FogApi
Import-Module FogApi;
# go obtain your fog server and user api tokens from the fog web gui then put them in this command
Set-FogServerSettings -fogApiToken 'your-server-token' -fogUserToken 'your-user-token' fog-server 'your-fog-server-hostname';
You’ll need to do that above setup for each location to connect to the api
Now you can get the images and store them as json files, could do 1 big one and could use other file formats, this example will create a json file for each image you have and store it in \server\share\fogImages which you should of course to change to some share you have access to.
This is a function you could paste into powershell and change that path using the parameter -exportPath "yourPath\here"
function Export-FogImageDefinitions {
[cmdletBinding()]
param (
$exportPath = "\\sever\share\fogImages"
)
$images = Get-FogImages;
$images | Foreach-object {
$name = $_.name;
$_ | ConvertTo-Json | Out-File -encoding oem "$exportPath\$name.json";
}
}
So you can copy and paste that (or save it into a .ps1 you dotsource, I may also just add it as a function in the fogAPi module as it would be handy for other users especially when migrating servers.)
You’d run it like this (after having setup your fog api connection Export-FogImageDefinitions -exportPth "some\path\here"
Now you have them all in json format on some share so you need an import command
Now this one I can’t easily test at the moment and may need a little bit of TLC, I based the fields to pass in on the ones defined in the matching class https://github.com/FOGProject/fogproject/blob/master/packages/web/lib/fog/image.class.php
This is the function you’d run on the other fog servers after configuring the powershell module for the destination fog server on that destination network.
EDIT: I adjusted this one after some testing. The api will ignore the old id automatically so it doesn’t matter if you pass that and you can pass all the other information that was exported as well, so no need to filter out anything with Select-Object, in fact you can just pass the raw json files
Function Import-FogImageDefinitions {
[cmdletBinding()]
param(
$importPath = "/images/imageDefinitions"
)
$curImages = Get-FogImages;
#get the json files you exported into the given path
$imageJsons = Get-ChildItem $importPath\*.json;
$imageJsons | Foreach-Object {
# get the content of the json, convert it to an object, and create the image definition
#create the image on the new server if it doesn't already exist
if ($curImages.name -contains $_.baseName) {
#this will assume the exported definition is the most up to date definition and update the image definition.
Update-FogObject -type object -coreObject image -jsonData (Get-Content $_.Fullname -raw);
} else {
New-FogObject -type object -coreObject image -jsondata (Get-Content $_.Fullname -raw)
}
}
}
So you copy paste this function into powershell and run import-fogImageDefinitions -importPath \\path\to\where\you\exported\images
That should do the trick.
Also, I believe that all of this will work in the linux version of powershell as well if you don’t have windows in your environment or if you wanted to have all of this running on the fog servers themselves. I also didn’t include what hosts have it assigned as that would probably be different on different servers. That’s also possible to export and import if the hosts are all the same.
You could also take this example and expand on it and get things automated via scheduled tasks on a windows system or cron on the fog servers so it essentially auto-replicates these definitions as you add new ones. If you want more information or more guidance on using the api for this let me know