@@ -710,6 +710,61 @@ client.collections.update("Songs_Alias", "PopSongs");
710710client.collections.delete(" Songs_Alias " );
711711```
712712
713+ ### Managing collection backups
714+
715+ ```java
716+ // Start a backup:
717+ Backup backup = client.backup.create(
718+ " backup_1" , " filesystem" ,
719+ bak -> bak
720+ .includeCollections(" Songs " , " Artists " )
721+ .compressionLevel(CompressionLevel.BEST_COMPRESSION)
722+ .cpuPercentage(30)
723+ );
724+
725+ // By default, the client does not monitor the backup status.
726+ // The above method returns as soon as the server acknowledges
727+ // the request and starts to process it.
728+ //
729+ // Now you can poll backup status to know when it is succeedes (or fails).
730+
731+ Backup status = client.backup.getCreateStatus(backup.id(), backup.backend());
732+ if (status.status() == BackupStatus.SUCCESSFUL) {
733+ System.out.println(" Yay ! " );
734+ System.exit(0);
735+ }
736+
737+ // Backups may take a write to complete. To block the current thread until
738+ // the execution completes, call Backup::waitForCompletion(WeaviateClient).
739+ //
740+ // Notice that, while we use `backup` object we can also call it on the `status`,
741+ // as both will have sufficient information to identify the backup operation.
742+
743+ try {
744+ Backup completed = backup.waitForCompletion(client);
745+ assert completed.errors() == null : " completed with errors" ;
746+ } catch (TimeoutException e) {
747+ System.out.exit(1);
748+ }
749+
750+ // List exists backups:
751+ List<Backup> allBackups = client.backup.list();
752+
753+ // Restore from the first backup:
754+ var first = allBackups.getFirst();
755+ client.backup.restore(first.id(), first.backend());
756+
757+ // Similarly, wait until the restore is complete using Backup::waitForCompletion.
758+ // It is possible to set a custom timeout and polling interval using a familiar Tucked Builder pattern:
759+
760+ var restoring = client.backup.getRestoreStatus(first.id(), first.backend());
761+ var restored = restoring.waitForCompletion(client, wait -> wait
762+ .timeout(Duration.ofMinutes(30))
763+ .interval(Duration.ofMinutes(5)));
764+
765+ assert restored.errors() == null : " restored with errors" ;
766+ ```
767+
713768## Useful resources
714769
715770- [Documentation](https://weaviate.io/developers/weaviate/current/client-libraries/java.html).
0 commit comments