Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reading and writing backups as tar archives #59535

Merged
merged 36 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
eb4ec0e
Add support for reading and writing backups as a
josh-hildred Jan 19, 2024
1eb4cdf
Add unit test coverage for ArchiveReaders
josh-hildred Feb 5, 2024
f9c0c99
Fix issue with LibArchiveWriter setCompression method
josh-hildred Feb 5, 2024
3c77237
getAllFiles now uses correct StreamInfo
josh-hildred Feb 6, 2024
e1fc5c8
Add archive unit tests
josh-hildred Feb 7, 2024
ac6d743
Address review comments
josh-hildred Feb 9, 2024
4c1ac01
Update src/IO/Archives/LibArchiveReader.cpp
josh-hildred Feb 9, 2024
48ad506
Cleaned up the uses of the libarchive structs
josh-hildred Feb 12, 2024
c53021f
Fix formating
josh-hildred Feb 14, 2024
dc74ceb
Fix formating
josh-hildred Feb 14, 2024
1bb9115
Add documentation
josh-hildred Feb 14, 2024
d0776e5
Fixes tidy issue and error formating for test
josh-hildred Feb 14, 2024
ef7a66b
Update error messages and error handling
josh-hildred Feb 15, 2024
2e2b89f
Fix whitespace
josh-hildred Feb 15, 2024
5fdeebf
Fix parameter naming
josh-hildred Feb 15, 2024
e085b0f
Update src/IO/Archives/IArchiveWriter.h
josh-hildred Feb 20, 2024
f94b5e9
Update src/IO/Archives/LibArchiveReader.cpp
josh-hildred Feb 20, 2024
84814f2
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 20, 2024
714fdeb
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 20, 2024
c3118ca
Address review comments
josh-hildred Feb 20, 2024
92b446a
Add support for tar archive compression
josh-hildred Feb 20, 2024
79aec12
Update docs
josh-hildred Feb 20, 2024
8bc968b
Fix tar integration test 
josh-hildred Feb 20, 2024
c02502b
Removed unused error code
josh-hildred Feb 20, 2024
f7ab6b9
Move tar compression extension definitions
josh-hildred Feb 21, 2024
84a3a05
Update src/IO/Archives/LibArchiveReader.cpp
josh-hildred Feb 21, 2024
f145b49
Update src/IO/Archives/LibArchiveWriter.h
josh-hildred Feb 21, 2024
6b32271
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 21, 2024
5963b67
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 21, 2024
0fe15f0
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 21, 2024
1ce6256
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 21, 2024
f34ef71
Update src/IO/Archives/LibArchiveWriter.cpp
josh-hildred Feb 21, 2024
e6134bb
Address review comments
josh-hildred Feb 21, 2024
ca9a6f8
add support for .tar.zst and tar.xz
josh-hildred Feb 21, 2024
fe67293
Add support for lzma
josh-hildred Feb 26, 2024
58a8658
Use std::array and std::any_of
josh-hildred Feb 26, 2024
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
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;

josh-hildred marked this conversation as resolved.
Show resolved Hide resolved
/// 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
Loading
Loading