Commit 22fcc500 authored by Patricio Bruna's avatar Patricio Bruna

Added api.backup() and bumped version to 0.3.9

parent 355ff495
......@@ -192,6 +192,20 @@ client.getAllAccounts(query_object, callback);
## Server Operations
### Backup
Do a backup `<account>` elements are required when `method=full` and server is running in standard backup mode. If server is running in auto-grouped backup mode, omit the account list in full backup request to trigger auto-grouped backup. If account list is specified, only those accounts will be backed up.
Full documentation: https://files.zimbra.com/docs/soap_api/8.7.0/api-reference/zimbraAdmin/Backup.html
The first param is the `Mailbox Server`. You need direct access to the `7071` port on this server.
```javascript
const backupRequest = {blobs: 'exclude', secondaryBlobs: 'exclude', searchIndex: 'exclude'};
const accounts = ['account2@example.com', 'account1@example.com'];
api.backup("localhost", backupRequest, null, accounts, callback);
// {label: "full-20160830.222823.315"}
```
### Get All Volumes
Get All Volumes from the server. [This link](https://files.zimbra.com/docs/soap_api/8.7.0/api-reference/zimbraAdmin/GetAllVolumes.html) has full documentation
......
{
"name": "zimbra-admin-api-js",
"version": "0.3.8",
"version": "0.3.9",
"main": "src/index.js",
"engines": {
"node": ">=6.2"
......
......@@ -668,6 +668,22 @@ class ZimbraAdminApi {
return this.performRequest(request_data);
}
// Full Doc: https://files.zimbra.com/docs/soap_api/8.7.0/api-reference/index.html
backup(server, backup, fileCopier, account, callback) {
if (server) {
this.client.options.url = "https://" + server + ":7071/service/admin/soap";
}
backup = backup || {};
if (!backup.method) backup.method = "full";
account = account || "all";
const request_data = this.buildRequestData(`Backup`, callback);
request_data.params.params.backup = backup;
request_data.params.params.backup.fileCopier = fileCopier;
request_data.params.params.backup.account = this.dictionary.convertToZimbraArray(account, 'name');
request_data.parse_response = ResponseParser.backupResponse;
return this.performRequest(request_data);
}
// TODO: Fix this ugly FCKing Code
batchCountAccounts(domains_ids, callback) {
const that = this;
......
......@@ -87,11 +87,14 @@ class Dictionary {
// This return a string or array of objects
// useful for Zimbra functions that works with both
convertToZimbraArray (object) {
convertToZimbraArray (object, attribute) {
const elements = [].concat.apply([], [object]);
const result = [];
elements.forEach((el) => {
result.push({ '_content': el });
const obj = {};
if (attribute) obj[attribute] = el;
if (!attribute) obj['_content'] = el;
result.push(obj);
});
return result;
}
......
......@@ -48,6 +48,11 @@ class ResponseParser {
return result;
}
static backupResponse(data, request_data, callback) {
const response_object = data.get().BackupResponse.backup[0];
return callback(null, response_object);
};
static batchResponse(data, callback) {
const response_object = data.options.response.BatchResponse;
if(response_object.Fault && response_object.Fault.length >= 1 ) {
......
......@@ -1083,6 +1083,27 @@ var zimbraAdminPassword = process.env.ZIMBRA_PASSWORD || '12345678';
done();
});
});
it('Backup: it should make the backup', function(done){
this.timeout(35000);
if (!process.env.TEST_ZIMBRA_NE) {
done();
return true;
}
var auth = {
'url': process.env.ZIMBRA_NE_URL,
'user': process.env.ZIMBRA_NE_USER,
'password': process.env.ZIMBRA_NE_PASSWORD
};
let api = new ZimbraAdminApi(auth);
const backupRequest = {blobs: 'exclude', secondaryBlobs: 'exclude', searchIndex: 'exclude'};
const accounts = ['david@zboxapp.com', 'natalia@smartprint.cl'];
api.backup("192.168.0.154", backupRequest, null, accounts, function(err, data){
if (err) console.log(err);
expect(data.label).to.exist;
done();
});
})
});
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment