Skip to content

Commit

Permalink
Merge pull request #30 from hostari/backup_and_restore
Browse files Browse the repository at this point in the history
Backup and restore
  • Loading branch information
Weltinio authored Nov 15, 2022
2 parents 9050bd7 + dca55a5 commit 96fe39f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: fleet_app_client
version: 0.2.5
version: 0.2.6

authors:
- Pauline De Polonia <[email protected]>
Expand Down
70 changes: 70 additions & 0 deletions src/fleet_app/backup_and_restore.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module FleetApp
class Server
# Back up the loaded world of the specified game then restore and load the selected world.
#
# The server will need to be stopped, the current world will be backed up,
# the target world will be restored, then the server will be restarted.
#
# Use `host` to specify the queue name in brooce to send to.
# For example, use `2013191.xyz` if the command should be executed on tms1.
# If you don't know which queue to send to, the SRE lead should be able to advise you
# based on how they configured brooce.
#
# Use `game_name` to specify the game you are sending a brooce command for.
# See: `FleetApp::Game` for possible values.
#
# Use `server_id` to specify the internal Hostari id. Can be a `subscription_id` from GamesSite,
# or a `server_id` from VSH.
#
# `body` is an optional, JSON-formatted string that is sent as the request body which defaults to an empty string.
# This is used to override the default command in fleet app.
# For example, you can send this: `{command: "echo 'foobar'"}.to_json`
#
# `environment` is an optional string that specifies which fleet app to send the request to.
def self.backup_and_restore(
host : String, game_name : String, server_id : String, body : String = "", environment : String = "production",
username : String = "", loaded_world_name : String = "", loaded_backup_date : String = "", server_type : String = "",
loaded_world_id : String = "", loaded_backup_id : String = "", restoration_url : String = "",
restoration_world_name : String = "", restoration_backup_date : String = "", restoration_world_id : String = ""
)
FleetApp::ClientWrapper.new(environment).post(
game_name: game_name,
path: ApiPath.new(
game_name, server_id, host, "backup_and_restore", {
"username" => username, "loaded_world_name" => loaded_world_name,
"loaded_backup_date" => loaded_backup_date, "server_type" => server_type,
"environment" => environment, "loaded_world_id" => loaded_world_id,
"loaded_backup_id" => loaded_backup_id, "restoration_url" => restoration_url,
"restoration_world_name" => restoration_world_name,
"restoration_backup_date" => restoration_backup_date,
"restoration_world_id" => restoration_world_id,
}).path,
body: body
)
end

def self.backup_and_restore_with_auth(
host : String, game_name : String, server_id : String, basic_auth : String, body : String = "",
environment : String = "production", username : String = "", loaded_world_name : String = "",
loaded_backup_date : String = "", server_type : String = "", loaded_world_id : String = "",
loaded_backup_id : String = "", restoration_url : String = "", restoration_world_name : String = "",
restoration_backup_date : String = "", restoration_world_id : String = ""
)
FleetApp::ClientWrapper.new(environment).post_with_auth(
game_name: game_name,
path: ApiPath.new(
game_name, server_id, host, "backup_and_restore", {
"username" => username, "loaded_world_name" => loaded_world_name,
"loaded_backup_date" => loaded_backup_date, "server_type" => server_type,
"environment" => environment, "loaded_world_id" => loaded_world_id,
"loaded_backup_id" => loaded_backup_id, "restoration_url" => restoration_url,
"restoration_world_name" => restoration_world_name,
"restoration_backup_date" => restoration_backup_date,
"restoration_world_id" => restoration_world_id,
}).path,
body: body,
basic_auth: basic_auth
)
end
end
end
2 changes: 1 addition & 1 deletion src/fleet_app_client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "json"
require "http/client"

class FleetAppClient
VERSION = "0.2.5"
VERSION = "0.2.6"
HOST = "fleet.hostari.com"
SANDBOX_HOST = "sandbox-#{HOST}"
DEVELOPMENT_HOST = "localhost:2450"
Expand Down

0 comments on commit 96fe39f

Please sign in to comment.