UrBackup Server API Client for Node.js
The `urbackup-server-api` module provides a Node.js interface for programmatic interaction with the UrBackup server's web API. It enables comprehensive management and monitoring of backup operations, including manipulating server and client settings, group management, task monitoring, initiating/stopping backups, accessing live logs, and fetching backup history. The current stable version is 0.92.2, indicating it is under active development and has not yet reached a 1.0.0 release. The project exhibits an iterative release cadence, with minor versions introducing new features and occasional method signature adjustments. Its primary differentiation lies in simplifying the automation and integration of UrBackup server administration directly within Node.js applications, making it valuable for server administrators and developers. Due to its pre-1.0 status, users should be aware that method signatures and functionality may change without major version bumps, necessitating a review of the CHANGELOG before updates.
Common errors
-
connect ECONNREFUSED <ip-address>:<port>
cause The UrBackup server is either not running, not accessible at the specified URL and port, or a firewall is blocking the connection.fixVerify that the UrBackup server is online and reachable from your Node.js application. Check the `url` parameter in your `UrbackupServer` constructor and ensure no firewall rules are preventing access. -
Error: Invalid username or password
cause The credentials provided to the `UrbackupServer` constructor (username and password) are incorrect for accessing the UrBackup API.fixDouble-check the `username` and `password` parameters against your UrBackup server's user credentials. Ensure the user has the necessary API access rights. -
Error: self-signed certificate in certificate chain (CODE: DEPTH_ZERO_SELF_SIGNED_CERT)
cause The UrBackup server is using a self-signed SSL/TLS certificate, which Node.js does not trust by default.fixFor development, you can temporarily set `process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'` (highly discouraged for production). The correct fix is to configure a trusted SSL certificate on your UrBackup server or provide Node.js with the necessary CA certificate to trust the self-signed certificate.
Warnings
- breaking The module is currently in pre-1.0.0 release. Method signatures and functionality may change without notice between minor versions. Always review the `CHANGELOG.md` before updating.
- breaking In version 0.92.0, the `getGroupMembers()` method changed its precedence. If both `groupId` and `groupName` are provided, `groupId` will now take precedence.
- gotcha Disabling TLS certificate validation via `process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'` is strongly discouraged for production use as it bypasses critical security checks, making your application vulnerable to man-in-the-middle attacks.
Install
-
npm install urbackup-server-api -
yarn add urbackup-server-api -
pnpm add urbackup-server-api
Imports
- UrbackupServer
const { UrbackupServer } = require('urbackup-server-api');import { UrbackupServer } from 'urbackup-server-api'; - UrbackupServer
import UrbackupServer from 'urbackup-server-api';
import { UrbackupServer } from 'urbackup-server-api'; - UrbackupServer
import * as UrbackupAPI from 'urbackup-server-api';
import { UrbackupServer } from 'urbackup-server-api';
Quickstart
import { UrbackupServer } from 'urbackup-server-api';
// When troubleshooting TSL connections with self-signed certificates, you may try to disable certificate validation.
// Keep in mind that it's strongly discouraged for production use.
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const server = new UrbackupServer({
url: process.env.URBACKUP_URL ?? 'http://127.0.0.1:55414',
username: process.env.URBACKUP_USERNAME ?? 'admin',
password: process.env.URBACKUP_PASSWORD ?? 'secretpassword',
});
(async () => {
try {
// Check if server is currently busy
const activities = await server.getCurrentActivities();
console.log(`Server Busy: ${activities.length > 0}`);
// Get a list of clients in the 'prod' group
const prodClients = await server.getGroupMembers({ groupName: 'prod' });
console.log('Production Clients:', prodClients.map(c => c.name));
// Get production clients with failed image backup
const failedClients = await server.getFailedClients({ groupName: 'prod', includeFileBackups: false });
console.log('Failed Image Backups in Prod:', failedClients.map(c => c.name));
// Get all clients without both file and image backups
const blankClients = await server.getBlankClients();
console.log('Clients without any backups:', blankClients.map(c => c.name));
} catch (error) {
console.error('An error occurred:', error.message);
}
})();