Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/collections/backup/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BackupReturn,
BackupStatusArgs,
BackupStatusReturn,
ListBackupOptions,
} from './types.js';

export const backup = (connection: Connection): Backup => {
Expand Down Expand Up @@ -205,8 +206,12 @@ export const backup = (connection: Connection): Backup => {
}
: parseResponse(res);
},
list: (backend: Backend): Promise<BackupReturn[]> => {
return connection.get<BackupReturn[]>(`/backups/${backend}`);
list: (backend: Backend, opts?: ListBackupOptions): Promise<BackupReturn[]> => {
let url = `/backups/${backend}`;
if (opts?.startedAtAsc) {
url += '?order=asc';
}
return connection.get<BackupReturn[]>(url);
},
};
};
Expand Down Expand Up @@ -261,7 +266,8 @@ export interface Backup {
/** List existing backups (completed and in-progress) created in a given backend.
*
* @param {Backend} backend Backend whence to list backups.
* @param {ListBackupOptions} [opts] The options available when listing backups.
* @returns {Promise<BackupReturn[]>} The response from Weaviate.
* */
list(backend: Backend): Promise<BackupReturn[]>;
*/
list(backend: Backend, opts?: ListBackupOptions): Promise<BackupReturn[]>;
}
30 changes: 30 additions & 0 deletions src/collections/backup/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,36 @@ describe('Integration testing of backups', () => {
});
});

requireAtLeast(1, 33, 2).it('get all backups in ascending order', async () => {
await clientPromise.then(async (client) => {
await client.collections.create({ name: 'TestListBackupsAsc' }).then((col) => col.data.insert());

const wantBackups: string[] = [];
for (let i = 0; i < 3; i++) {
wantBackups.push(
await client.backup
.create({
backupId: randomBackupId(),
backend: 'filesystem',
includeCollections: ['TestListBackupsAsc'],
waitForCompletion: true,
})
.then((res) => res.id)
);
}

const sortAscending = true;
const gotBackups = await client.backup.list('filesystem', { startedAtAsc: sortAscending });

// There may be other backups created in other tests;
expect(gotBackups.length).toBeGreaterThanOrEqual(wantBackups.length);
// Expect the backups to be sorted in ascending order
expect(
gotBackups.every((value, idx, a) => idx === 0 || a[idx - 1].startedAt! <= value.startedAt!)
).toBe(sortAscending);
});
});

function randomBackupId() {
return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
}
Expand Down
11 changes: 11 additions & 0 deletions src/collections/backup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export type BackupReturn = BackupStatusReturn & {
backend: Backend;
/** The collections that were included in the backup */
collections: string[];
/** Timestamp when the backup process started */
startedAt?: Date;
/** Timestamp when the backup process completed (successfully or with failure) */
completedAt?: Date;
/** Size of the backup in Gibs */
size?: number;
};

/** Configuration options available when creating a backup */
Expand Down Expand Up @@ -72,3 +78,8 @@ export type BackupCancelArgs = {
/** The backend to use for the backup. */
backend: Backend;
};

/** The options available when listing backups. */
export type ListBackupOptions = {
startedAtAsc?: boolean;
};