Skip to content

Commit

Permalink
Merge pull request #59535 from josh-hildred/tar_support
Browse files Browse the repository at this point in the history
Add support for reading and writing backups as tar archives
  • Loading branch information
antonio2368 committed Mar 1, 2024
2 parents 891689a + 58a8658 commit 5104029
Show file tree
Hide file tree
Showing 18 changed files with 1,050 additions and 143 deletions.
2 changes: 1 addition & 1 deletion contrib/libarchive-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ if (TARGET ch_contrib::zlib)
endif()

if (TARGET ch_contrib::zstd)
target_compile_definitions(_libarchive PUBLIC HAVE_ZSTD_H=1 HAVE_LIBZSTD=1)
target_compile_definitions(_libarchive PUBLIC HAVE_ZSTD_H=1 HAVE_LIBZSTD=1 HAVE_LIBZSTD_COMPRESSOR=1)
target_link_libraries(_libarchive PRIVATE ch_contrib::zstd)
endif()

Expand Down
22 changes: 22 additions & 0 deletions docs/en/operations/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ RESTORE TABLE test.table PARTITIONS '2', '3'
FROM Disk('backups', 'filename.zip')
```
### Backups as tar archives
Backups can also be stored as tar archives. The functionality is the same as for zip, except that a password is not supported.
Write a backup as a tar:
```
BACKUP TABLE test.table TO Disk('backups', '1.tar')
```
Corresponding restore:
```
RESTORE TABLE test.table FROM Disk('backups', '1.tar')
```
To change the compression method, the correct file suffix should be appended to the backup name. I.E to compress the tar archive using gzip:
```
BACKUP TABLE test.table TO Disk('backups', '1.tar.gz')
```
The supported compression file suffixes are `tar.gz`, `.tgz` `tar.bz2`, `tar.lzma`, `.tar.zst`, `.tzst` and `.tar.xz`.
### Check the status of backups
The backup command returns an `id` and `status`, and that `id` can be used to get the status of the backup. This is very useful to check the progress of long ASYNC backups. The example below shows a failure that happened when trying to overwrite an existing backup file:
Expand Down
2 changes: 1 addition & 1 deletion src/Backups/BackupImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ void BackupImpl::writeFile(const BackupFileInfo & info, BackupEntryPtr entry)

const auto write_info_to_archive = [&](const auto & file_name)
{
auto out = archive_writer->writeFile(file_name);
auto out = archive_writer->writeFile(file_name, info.size);
auto read_buffer = entry->getReadBuffer(writer->getReadSettings());
if (info.base_size != 0)
read_buffer->seek(info.base_size, SEEK_SET);
Expand Down
2 changes: 2 additions & 0 deletions src/IO/Archives/IArchiveWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class IArchiveWriter : public std::enable_shared_from_this<IArchiveWriter>, boos
/// of the function `writeFile()` should be destroyed before next call of `writeFile()`.
virtual std::unique_ptr<WriteBufferFromFileBase> writeFile(const String & filename) = 0;

virtual std::unique_ptr<WriteBufferFromFileBase> writeFile(const String & filename, size_t size) = 0;

/// Returns true if there is an active instance of WriteBuffer returned by writeFile().
/// This function should be used mostly for debugging purposes.
virtual bool isWritingFile() const = 0;
Expand Down

0 comments on commit 5104029

Please sign in to comment.