Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 8 additions & 3 deletions src/collections/backup/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ export const backup = (connection: Connection): Backup => {
}
: parseResponse(res);
},
list: (backend: Backend): Promise<BackupReturn[]> => {
return connection.get<BackupReturn[]>(`/backups/${backend}`);
list: (backend: Backend, sortAscending?: boolean): Promise<BackupReturn[]> => {
let url = `/backups/${backend}`;
if (sortAscending) {
url += '?order=asc';
}
return connection.get<BackupReturn[]>(url);
},
};
};
Expand Down Expand Up @@ -261,7 +265,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 {sortAscending} [boolean] Sort list of backups in ascending order based on creation time. Default is descending order.
* @returns {Promise<BackupReturn[]>} The response from Weaviate.
* */
list(backend: Backend): Promise<BackupReturn[]>;
list(backend: Backend, sortAscending?: boolean): 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', 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
6 changes: 6 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