Files
duplicati/Duplicati/Library/Backend/S3/IS3Client.cs
T
Kenneth Skovhede 0f81b42146 Add support for remote locks
This PR adds support for locking files if the backend supports it.

To activate locking, set the option `--file-lock-duration=30D` and the backup will lock the files.

If the database is rebuilt with the intention of continuing the backups, use the option `--repair-refresh-lock-info` which will update lock information in the database after recreating the database.

The locking works by asking the backend to lock files after a backup has completed.

The implementation keeps track of which files are currently assigned a lock and prevents attempting to delete the files that are currently locked.

Note that the bucket should not have a default lock policy as Duplicati needs to finish the backup before the locking is applied.

In this initial version, Azure Blob Storage, B2, S3 and iDrive are supported with locking.

The CLI is updated to allow setting locks on a specific version. The backend tool is updated to allow setting locks on specific files.
2025-12-14 17:17:48 +01:00

108 lines
5.6 KiB
C#

// Copyright (C) 2025, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using Duplicati.Library.Interface;
namespace Duplicati.Library.Backend
{
public interface IS3Client : IDisposable
{
/// <summary>
/// List all objects in a bucket
/// </summary>
/// <param name="bucketName">The bucket name</param>
/// <param name="prefix">The prefix to filter the objects</param>
/// <param name="recursive">Whether to list recursively</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>The list of objects</returns>
IAsyncEnumerable<IFileEntry> ListBucketAsync(string bucketName, string prefix, bool recursive, CancellationToken cancellationToken);
/// <summary>
/// Add a new bucket
/// </summary>
/// <param name="bucketName">The name of the bucket to create</param>
/// <param name="cancelToken">The cancellation token</param>
/// <returns>A task representing the asynchronous operation</returns>
Task AddBucketAsync(string bucketName, CancellationToken cancelToken);
/// <summary>
/// Delete an object from a bucket
/// </summary>
/// <param name="bucketName">The name of the bucket</param>
/// <param name="keyName">The name of the object to delete</param>
/// <param name="cancelToken">The cancellation token</param>
/// <returns>>A task representing the asynchronous operation</returns>
Task DeleteObjectAsync(string bucketName, string keyName, CancellationToken cancelToken);
/// <summary>
/// Rename an object in a bucket
/// </summary>
/// <param name="bucketName">The name of the bucket</param>
/// <param name="source">The source object name</param>
/// <param name="target">The target object name</param>
/// <param name="cancelToken">The cancellation token</param>
/// <returns>>A task representing the asynchronous operation</returns>
Task RenameFileAsync(string bucketName, string source, string target, CancellationToken cancelToken);
/// <summary>
/// Copies the object contents into the target stream
/// </summary>
/// <param name="bucketName">The name of the bucket</param>
/// <param name="keyName">The name of the object to copy</param>
/// <param name="target">The target stream to copy the object contents into</param>
/// <param name="cancelToken">The cancellation token</param>
/// <returns>>A task representing the asynchronous operation</returns>
Task GetFileStreamAsync(string bucketName, string keyName, Stream target, CancellationToken cancelToken);
/// <summary>
/// Gets the DNS hostnames used for the S3 client
/// </summary>
/// <returns>The DNS hostnames used for the S3 client</returns>
string? GetDnsHost();
/// <summary>
/// Adds a file stream to the bucket
/// </summary>
/// <param name="bucketName">The name of the bucket</param>
/// <param name="keyName">The name of the object to create</param>
/// <param name="source">The source stream to upload</param>
/// <param name="cancelToken">The cancellation token</param>
/// <returns>>A task representing the asynchronous operation</returns>
Task AddFileStreamAsync(string bucketName, string keyName, Stream source, CancellationToken cancelToken);
/// <summary>
/// Gets the current object lock expiration timestamp for a remote file, if available.
/// </summary>
/// <param name="bucketName">The bucket containing the object.</param>
/// <param name="keyName">The full object key.</param>
/// <param name="cancelToken">The cancellation token.</param>
/// <returns>The UTC expiration timestamp if present, otherwise <c>null</c>.</returns>
Task<DateTime?> GetObjectLockUntilAsync(string bucketName, string keyName, CancellationToken cancelToken);
/// <summary>
/// Applies or updates the object lock expiration for a remote file.
/// </summary>
/// <param name="bucketName">The bucket containing the object.</param>
/// <param name="keyName">The full object key.</param>
/// <param name="lockUntilUtc">The UTC timestamp until which the object should remain locked.</param>
/// <param name="cancelToken">The cancellation token.</param>
Task SetObjectLockUntilAsync(string bucketName, string keyName, DateTime lockUntilUtc, CancellationToken cancelToken);
}
}