Add Backup Server

Virtualizor supports three types backup viz LOCAL, SSH and FTP. In case of LOCAL backups the VPS image is backed up on the directory of the node server itself. For remote backups you need to add the details of the remote backup servers which can be done using the Add Backup Server API. The API response will contain "done" as "true" after successful addition of the backup server.

After adding the backup server you need to make sure that it is added in the backup plan for the VPS files to be backed up. Also use the Test Backup Connectivity API to test the connection to the backup server after it has been added.

For more information, please refer this Backup Server guide.

HTTP Request

https://hostname:4085/index.php?act=addbackupservers

Parameters

NameMethodValueDescriptionRequired
actGETaddbackupserversThe action specified to perform operation and return "done" as "true" after the backup server has been addedYes
hostnamePOSTtextAny one of the Hostname of the Backup Server or IP address can be addedYes
namePOSTtextUnique name for the Backup ServerYes
typePOSTtextType of the Server (FTP / SSH)Yes
usernamePOSTtextUsername for the backupserverYes
passwordPOSTtextPassword of the backupserverNo
portPOSTIntPort numberYes
ssh_keyPOSTIntPass 1 to enable ssh key authentication
No
sshpub_keyPOSTtextProvide the public key (compulsory if ssh_key is passed).
No
sshpri_keyPOSTtextProvide the Private key (compulsory if ssh_key is passed).No
gen_keyPOSTIntPass 1 to generate keys for the backup server (In return you will get the prublic and private keys).
No

How to use Generated keys?

When you pass gen_key while adding backup server you will get public key and private key in response of API. The following is the sample response.

[keys] => Array
        (
            [public_key] => ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFvWP35.... root@lxc

            [private_key] => -----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAxb1j9+b66jRBBPRtVq+znA9nlqiGtW1WgcDN+0T0PTBb8Py5
CuWiUFQ4spQyqkRXi9Y1JT4g3+tAFHEpyCjZttoZivWE5gF/sL8IpG4pUmcVOwut
yjiWW7yglPSVLsqIyCP4ooFJGQ8Bokx7k+zORlrLfAJC+F6fwIe/RyxjZOdD88S9......

[path] => /var/virtualizor/ssh-keys/
        )

After getting the keys you will need to add the public key on backup server in /root/.ssh/authorized_keys

Sample Code

<?php

    require_once('/usr/local/virtualizor/sdk/admin.php');

    $key =  'your_api_key';
    $pass = 'your_api_pass';
    $ip = 'your_server_ip';

    $admin = new Virtualizor_Admin_API($ip, $key, $pass);

    $post = array();
    $post['hostname'] = 'testhost';
    $post['name'] = 'backupstest';
    $post['type'] = 'SSH';
    $post['username'] = 'test';
    $post['password'] = 'test123';
$post['gen_key'] = 1; //pass only if you want to generate new keys
$post['ssh_key'] = 1; //pass only if you want to use keys to authenticate
$post[
'sshpub_key'] = 'YOUR PUBLIC KEY'; //pass only if ssh_key is set
$post['sshpri_key'] = 'YOUR PRIVATE KEY'; //pass only if ssh_key is set $post['port'] = 22; $output = $admin->addbackupserver($post); print_r(json_encode($output)); ?>

Output

{
    "title": "Add Backup Server",
    "done": 2 //backup server ID,
    "timenow": 1535547543,
"keys" : { "public_key": ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB... root@lxc "private_key": -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEAskY2nbNvzokm89Fy2Uf5VEs5oD4YtsnX6+JEZ+LgpQcmlqpk yDtKf/o7PK81V9O9WLm81BD25S36O2onoqlHNEesZE8oyE2EDhbHNWKZla2PG+os aOBR2kYwKGxFgGI1+mRVfpNvO6uJQmCXaSUFisE50QNpuvBdPFaAgR8rF+jVZDEh NNHdRu/C8uimAjUI2bPyH0Ow2v6QtABBB81ch0T+vgmJmosBpFPcvIePFjzbyYYd uc3StSz6qk+iLJQjBthMwW6EqbS3LZ2akmNyBkBWOfxTVg/jJRGScoiPiJMPAucs cjHjIMbOpMEP7PUTooE1nzbmYtaojc54p6iCCwIDAQABAoIBADRmPOFnf4KGf6OE.... -----END RSA PRIVATE KEY----- "path": /var/virtualizor/ssh-keys/ }, "time_taken": "0.223" }
Was this page helpful?