CodeGuard

Developers

Databases

The Database resource type represents a database backup within the CodeGuard application. A database belongs to a Website.

Context

Requests to the Database resource can only be made by authenticated users. Requests must include a valid OAuth signature and key. See the OAuth section in the Appendix for more information.

Attributes

The following are the attributes associated with the Database resource. Whether they are required or optional is specified in the sections that follow.

id

Unique numeric ID used to identify the database resource in the CodeGuard application.

provider

This is the protocol to be used to connect to the host specified as hostname. Acceptable values for this field are mysql or mssql. Note: When using the 'mssql' provider, only direct authentication is permitted.

website_id

Numeric ID of the parent Website record. If no website_id is provided, the Database will not be associated with a Website record.

server_address

Database Hostname or IP address.

database_name

The name of the target database.

disabled

Indicates whether or not the backup is enabled. Disabled resources will not be scheduled for backups.

account

Username which has access to the database_name database.

password

Password associated with account. Note: This parameter is only used during the create action. It is never returned by other API requests.

port

Server port number for use with the server_name. (Default: 3306 for MySQL, 1433 for MS SQL)

authentication_mode

This service can has two modes: direct and ssh. The direct method will attempt to open a connection using a MySQL or MS SQL client on the specified server and port. The ssh method will create an SSH tunnel through server_name using the server_account and server_password credentials to connect to the database on server_name. Note: The following two attributes are required for SSH.

server_account

SSH username on server_address. Note: This field is only valid if the authenticationmode is ssh._

server_password

SSH password associated with server_account. Note: This field is only valid if the authenticationmode is ssh._

commit_id

The ID of the most recent backup represented as a SHA-1 hash.

activated

A boolean indication of whether or not the initial backup has been completed. Note: This parameter is for information purposes only and can not be modified via the API.

disk_usage

The size in bytes of the database backup stored in the CodeGuard system.

schedule_at

The desired time of day for this backup to begin, in UTC.

Create Databases

This method is used to create new database backup records.

URI: /database_backups

Method: POST

Required Attributes

The request will not succeed without these attributes.

Optional Attributes
Example Request
http post 'https://api.codeguard.com/database_backups?oauth_consumer_key=Ezc2doao056bb177yan4kLugYJu7y6zRrf0BQuEs&oauth_nonce=1234&oauth_signature=vLy35yGcDDoMkayjI3Sn0Ko70Os%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1334612979&oauth_token=Arvlr5wtNgcFYks22Gnvf0k9VnW0gl7jNx3vnGaV&oauth_version=1.0' website_id=184 server_address=dev.manuzak.com account=user password=password port=3306 database_name=test_restore server_account=user server_password=password authentication_mode=ssh
        
Example Response
{
            "database_backup":
            {
                "account":"user",
                "authentication_mode":"direct",
                "server_address":"dev.manuzak.com",
                "disk_usage":0,
                "database_name":"test_restore",
                "backup_state":0,
                "port":3306,
                "commit_id":"",
                "mysql_version":null,
                "id":12,
                "repo_size": 0,
                "last_backup_status":null,
                "disabled":false,
                "activated":true,
                "notifications_enabled":true,
                "website_id":141
            }
        }
        

Show Databases

This method is used to display information about a single database backup record.

URI: /database_backups/<DATABASE_BACKUP_ID>

Method: GET

Required Attributes

None

Optional Attributes

None

Example Request
curl -v -H "Content-type: application/json" -H "Accept: application/json" -X GET 'https://api.codeguard.com/websites/141/database_backups/12?oauth_consumer_key=u1xe85RrWhpJim3xslJb9GI9ENms6PmFjYDeTOgc&oauth_nonce=1234&oauth_signature=JxkBWtFneUDx02ArD1ZBR7NGmWs%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1307966160&oauth_token=qFFTIQszYZwHc4KmeZciyFjHT9XdcsRGrgkgwPQr&oauth_version=1.0'
        
Example Response
{
            "database_backup":
            {
                "account":"user",
                "authentication_mode":"direct",
                "server_address":"dev.manuzak.com",
                "disk_usage":0,
                "database_name":"test_restore",
                "backup_state":0,
                "port":3306,
                "commit_id":"",
                "mysql_version":null,
                "id":12,
                "repo_size": 0,
                "last_backup_status":null,
                "disabled":false,
                "activated":true,
                "notifications_enabled":true,
                "website_id":141
            }
        }
        

Edit Databases

This method is used to modify existing database backup records.

URI: /database_backups/<DATABASE_BACKUP_ID>

Method: PUT

Required Attributes

None

Optional Attributes
Example Request
http put 'https://api.codeguard.com/database_backups/12?oauth_consumer_key=Ezc2doao056bb177yan4kLugYJu7y6zRrf0BQuEs&oauth_nonce=1234&oauth_signature=vLy35yGcDDoMkayjI3Sn0Ko70Os%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1334612979&oauth_token=Arvlr5wtNgcFYks22Gnvf0k9VnW0gl7jNx3vnGaV&oauth_version=1.0'
        
Example Response
{
            "database_backup":
            {
                "account":"user",
                "authentication_mode":"direct",
                "server_address":"dev1.manuzak.com",
                "disk_usage":0,
                "database_name":"test_restore",
                "backup_state":0,
                "port":3306,
                "commit_id":"",
                "mysql_version":null,
                "id":12,
                "repo_size": 0,
                "last_backup_status":null,
                "disabled":false,
                "activated":true,
                "notifications_enabled":true,
                "website_id":141
            }
        }
        

Delete Databases

This method is used to delete existing CodeGuard Database resources.

URI: /database_backups/<id>

Method: DELETE

Required Attributes

None

Optional Attributes

None

Example Request
curl -v -H "Content-type: application/json" -H "Accept: application/json" -X DELETE 'https://api.codeguard.com/database_backups/3412?oauth_consumer_key=u1xe85RrWhpJim3xslJb9GI9ENms6PmFjYDeTOgc&oauth_nonce=1234&oauth_signature=JxkBWtFneUDx02ArD1ZBR7NGmWs%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1307966160&oauth_token=qFFTIQszYZwHc4KmeZciyFjHT9XdcsRGrgkgwPQr&oauth_version=1.0'
        

List Databases

This will display all Database records owned by a user.

URI: /database_backups

Method: GET

Optional Attributes

None

Required Attributes

None

Example Request
http get 'https://api.codeguard.com/database_backups?oauth_consumer_key=Ezc2doao056bb177yan4kLugYJu7y6zRrf0BQuEs&oauth_nonce=1234&oauth_signature=vLy35yGcDDoMkayjI3Sn0Ko70Os%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1334612979&oauth_token=Arvlr5wtNgcFYks22Gnvf0k9VnW0gl7jNx3vnGaV&oauth_version=1.0'
        
Example Response
(
        [0] => Array
            (
                [database_backup] => Array
                    (
                        [account] => db_user1
                        [authentication_mode] => direct
                        [website_id] => 1111
                        [server_address] => 192.168.1.1
                        [disk_usage] => 0
                        [database_name] => wordpress
                        [backup_state] => 0
                        [port] => 3306
                        [commit_id] =>
                        [mysql_version] => 5.1
                        [id] => 11
                        [repo_size] => 0
                        [mysqldump_version] => 5.1
                        [last_backup_status] =>
                        [disabled] => 0
                        [activated] => 1
                        [notifications_enabled] => 1
                    )

            )

        [1] => Array
            (
                [database_backup] => Array
                    (
                        [account] => db_user2
                        [authentication_mode] => direct
                        [website_id] => 1405
                        [server_address] => 10.0.222.3
                        [disk_usage] => 0
                        [database_name] => drupal
                        [backup_state] => 0
                        [port] => 3306
                        [commit_id] =>
                        [mysql_version] => 5.5
                        [id] => 18
                        [repo_size] => 0
                        [mysqldump_version] => 5.5
                        [last_backup_status] =>
                        [disabled] => 0
                        [activated] => 1
                        [notifications_enabled] => 1
                    )

            )
        )
        

Request Backup

This method will initiate an on-demand backup for a Database.

URI: /websites/<WEBSITE_ID>/database_backups/<DATABASE_BACKUP_ID>/request_backup

Method: POST

Required Attributes

None

Optional Attributes

None

Example Request
curl -v -H "Content-type: application/json" -H "Accept: application/json" -X POST 'https://api.codeguard.com/websites/973532/database_backups/832332/request_backup?oauth_consumer_key=u1xe85RrWhpJim3xslJb9GI9ENms6PmFjYDeTOgc&oauth_nonce=1234&oauth_signature=JxkBWtFneUDx02ArD1ZBR7NGmWs%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1307966160&oauth_token=qFFTIQszYZwHc4KmeZciyFjHT9XdcsRGrgkgwPQr&oauth_version=1.0'
        
Example Response

        {
            "status" : "success"
        }
        

Request Zip Download

This method will initiate the production of a zip file which contains the entire contents of the selected backup. During this process the selected backup, specified as COMMIT_ID, will be packaged as a single zip file and stored in Amazon S3. Upon completion, a perishable link will be provided to the customer so that they can retrieve the zip file. By default, these links expire after 1 week.

The desired backup and corresponding COMMIT_ID can be located using the List Backups request.

URI: /websites/<WEBSITE_ID>/database_backups/<DATABASE_BACKUP_ID>/commits/<COMMIT_ID>/download

Method: POST

Required Attributes

None

Optional Attributes

None

Example Request

          curl -v -H "Content-type: application/json" -H "Accept: application/json" -X POST 'https://api.codeguard.com/websites/973532/database_backups/5612/commits/4a46f80fb145fc626fe4d6c730788fd10c69fbb7/download?oauth_consumer_key=u1xe85RrWhpJim3xslJb9GI9ENms6PmFjYDeTOgc&oauth_nonce=1234&oauth_signature=JxkBWtFneUDx02ArD1ZBR7NGmWs%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1307966160&oauth_token=qFFTIQszYZwHc4KmeZciyFjHT9XdcsRGrgkgwPQr&oauth_version=1.0'
        
Example Response

        {
            "message" : "200"
        }
        

Request Restore

This method will initiate a full restore for a Database. During this process the selected backup, specified as COMMIT_ID, will be used to overwrite the existing, live database content. During this process tables are dropped, recreated and then repopulated with the data from the selected backup version.

The desired backup and corresponding COMMIT_ID can be located using the List Backups request.

URI: /websites/<WEBSITE_ID>/database_backups/<DATABASE_BACKUP_ID>/commits/<COMMIT_ID>/initiate_restore

Method: POST

Required Attributes

None

Optional Attributes

None

Example Request
curl -v -H "Content-type: application/json" -H "Accept: application/json" -X POST 'https://api.codeguard.com/websites/973532/database_backups/832332/commits/4a46f80fb145fc626fe4d6c730788fd10c69fbb7/initiate_restore?oauth_consumer_key=u1xe85RrWhpJim3xslJb9GI9ENms6PmFjYDeTOgc&oauth_nonce=1234&oauth_signature=JxkBWtFneUDx02ArD1ZBR7NGmWs%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1307966160&oauth_token=qFFTIQszYZwHc4KmeZciyFjHT9XdcsRGrgkgwPQr&oauth_version=1.0'
        
Example Response

        {
            "status" : "success"
        }
        

List IP Addresses

It is very important that our IP addresses be whitelisted on any firewall rules on your server. This call will return a list of our current IP addresses that are required for whitelisting. While our IP addresses don't often change, should they change, you will always have the updated list of IP addresses using this call.

This is public, so there is no need for authentication.

URI: /whitelist_addresses

Method: GET

Required Attributes

None

Optional Attributes

None

Example Request
curl -v -H "Content-type: application/json"  -H "Accept: application/json" -X GET 'https://api.codeguard.com/whitelist_addresses'
        
Example Response

          [
            "54.236.233.46",
            "54.236.233.28",
            "54.174.91.34",
            "54.174.153.212",
            "54.174.115.171",
            "54.236.209.91"
          ]