Commit Graph

859 Commits

Author SHA1 Message Date
2d5338f0b5 Fix TestEntryExcludeByAttribute on linux
Modern linux distros often make /tmp a tmpfs which does not
support xattrs, so this test will fail.
2023-10-07 21:05:19 -05:00
e3e8740010 Create distinct named module 2023-10-07 15:54:57 -05:00
518d02a57d Normalize and add options for backup, add more file flags options
- Move more function arguments to structs with some convenience
functions.
- Add a flag to enable backup/restore of file flags. It works a little
bit differently depending on system. Since we don't need to do anything
to get file flags on darwin/BSD, it's in the stat buffer so just save it.
For linux we have to open the file and do a
- Add the normalize flag to ReadAttributes. Implementation TBD.
- stub out common xattr file for doc comments
v0.1.0
2023-10-07 13:55:51 -05:00
58d21eb17a Refactor the BackupManager options interface some more
- Move the pref based (repository associated) options back
to init of the backup manager. This is still a bit of an unholy mess but
the existing setup is a little insane.
There are mostly runtime associated settings, like revision, tag, thread
count, quick mode, show stats. Then there are the more fuzzy ones,
like allow failures, patterns. However something like set-owner, mostly
likely that's going to be static for a "repository", same with
exclude by attribute. In any event things that make sense to be
associated with the repository preferences will stay in a backup mananger
initialization time options structure, and no more growing of the
arguments list - go doesn't look good there.

RestoreOptions for the more ephemeral run associated settings.
The Backup routine with it's large argument list stays for now, but
will get revamped if anything new gets added.
2023-10-07 13:55:51 -05:00
c151b21f5c Remove deprecated rand functions in tests
With requirement for golang 1.20 the deprecated rand functions
can be dropped. Do not have to call seed.
2023-10-07 13:55:51 -05:00
6d5cb4b7b9 Add metadata and special files restore options
Add options to control if xattrs and specials get restored. Add
file flag mask preference. It's a rough interface, but this is a niche
use case.

Refactoring of options passing since golang ergonomics are poor for long
parameter lists.
2023-10-07 13:55:51 -05:00
09637c69bc ReadFileFlags on linux minor fix
Add ignoring EINTR to syscall, set O_NOATIME on open, ignore
ENOTTY error (unsupported ioctl) to avoid massive spam for
non-exceptional failure on nonsupporting file systems
2023-10-07 13:55:51 -05:00
bede63f33f Fix hardlink to symlink naming bug
When creating cloned entries of hardlinked symlinks we have to
preserve the target link data in the entry obviously.
2023-10-07 13:55:51 -05:00
95063913ae Split out xattr and flags routines to new files 2023-10-07 13:55:51 -05:00
3481814562 Cleanup some of the unix code and don't pass ptr to iface to GetOwner
Don't bother using checked type assertion for stat since we are
guarded by specific build configuration, we should know the
correct type, and if not, panicing is fine.

Despite syscall being deprecated a decade ago, we still need it
for FileInfo and sys/windows still calls it as well.
2023-10-07 13:55:51 -05:00
9ff5484ec0 Fix some deprecated functions in windows code 2023-10-07 13:55:51 -05:00
a33bf0a21b Break up Restore options into struct 2023-10-07 13:55:51 -05:00
228ca7005c Improve error handling and setting of xattr and file flags
- Improve error handling of file flags and xattrs. You now get warnings
- file flags on *BSD/Darwin use a mask and combine with the user/superuser
mask to prevent spurious warnings. The mask is not yet implemented as
a preference
- error handling/report for reading special files
- bump to go 1.20 for errors.Join
2023-10-07 13:55:51 -05:00
23a3cce0ad RestoreMetadata improved error messages 2023-10-07 13:55:51 -05:00
8427c03b71 Remove unnecessary fileInfo indirection (it's already interface) 2023-10-07 13:55:51 -05:00
af89dd5e7b Remove obsolete fileEncoder 2023-10-07 13:55:51 -05:00
a479fa5197 Set file attributes before setting mode and owner. 2023-10-07 13:55:51 -05:00
986e6a6ef2 update readme 2023-10-07 13:55:51 -05:00
756a003fb3 Factor out hard link code for cross platform build
Move system specific code out of entry so the build continues to work on
Windows. Hard links are not currently supported on Windows, the behavior
is a no-op.
2023-10-07 13:55:51 -05:00
07c796a46b Fix and reorganize for build for FreeBSD
- the xattr handling of namespaces is different on BSD with the
xattr package, the user namespace is implicit
- Don't backup/exclude files with flag nodump on BSD/Darwin
2023-10-07 13:55:51 -05:00
f24e8d2cbb Don't rewrite existing special file 2023-10-07 13:55:51 -05:00
cfff4ff425 update readme 2023-10-07 13:55:51 -05:00
6c1600e8c8 Rename hardlink to hard link (two words) 2023-10-07 13:55:51 -05:00
807268d337 minor: missing variable assignment in CheckSnapshot, struct-tag 2023-10-07 13:55:51 -05:00
ab8fc0faa6 fix broken tests 2023-10-07 13:55:51 -05:00
8cd457447b Fix formatting of diagnostic some diagnostic messages 2023-10-07 13:55:51 -05:00
ee19d44403 Cleanup hardlinking code
This moves special file link data to the chunk fields like symlink
hardlinks.
2023-10-07 13:55:51 -05:00
b8c0b1f86e tweak the symlink hardlink chunk ids 2023-10-07 13:55:51 -05:00
059e74da17 Support backup of sockets
This only works on Linux. Darwin does not allow mknod of a socket.
Have not tested BSD.
2023-10-07 13:55:51 -05:00
31c131b9e3 gofmt some files 2023-10-07 13:55:51 -05:00
e01008a56b Fix handling of hardlinks and special files
Also, don't attempt xattr ops on special files on the BSD likes.

TODO: Should have a way to allow restore without special files,
otherwise very cumbersome for a regular user.
2023-10-07 13:55:51 -05:00
4934df4e08 Support for hardlinks to symlinks
This is a specialized use-case, but it is indeed possible to do this
and can be used if xattrs are attached to the symlink.
2023-10-07 13:55:51 -05:00
52e628ac93 Fix handling of xattrs with symlinks
Fix Linux, Darwin, and other BSD (untested) to allow proper
handling of xattrs with symlinks. On Linux we cannot use the f*
syscalls for symlinks because symlinks cannot be opened.
File flags must be handled differently on darwin and other BSD due
to the lack of the LCHFLAGS syscall on darwin, and the fact that it
is emulated in libc. However, we do have O_SYMLINK on darwin.
2023-10-07 13:55:51 -05:00
88c92da9bd Support backup and restore of special files on POSIX style systems
Special files are device nodes and named pipes. The necessity of the
former is clear, the latter is debatable.
In order to preserve backward compatibility, the device number is
encoded in the StartChunk/StartOffset fields of the entry.
2023-10-07 13:55:51 -05:00
fee1cb859e Don't overwrite symlinks if file already exists 2023-10-07 13:55:51 -05:00
e61f5c2192 Support backup and restore of hardlinks
This tracks inode/device from the stat info and creates backward
compatible snapshots that allow preserving hardlinks. Backwards
compatibility is preserved by saving a virtual inode number index in the
Link field of the file entry. Since this field was previously only used
for symlinks, this won't break old versions. Additionally, the entry
data is cloned so restoration with an old version works.

Current limitations are primarility with restore. They include:
- no command line option to prevent hard link restore
- if a file has the immutable or append only flag it will be set before
hardlinks are restored, so hardlinking will fail.
- if a partial restore includes a hardlink but not the parent
directories the hardlink will fail.

These will be solved by grouping restore of hardlinks together
with file, prior to applying final metadata.

- if a file is changed and is being rewritten by a restore hardlinks are
not preserved.
2023-10-07 13:55:51 -05:00
d3b7cdc02d Initial implementation of file/inode flags (Linux, BSD, darwin)
Basic support for BSD and Darwin style chflags (stat flags). Applies
these flags at the end of file restore.
Supports linux style ioctl_iflags(2) in a 2 step process. Flags that
need to be applied prior to writes such as compress and especially no-COW
are applied immediately upon file open.

The flags format is backwards compatible. An attribute starting with a
null byte is used to store flags in the entry attributes table. With
an old version of duplicacy the restore of this attribute should silently
fail (effectively be ignored).

Fixes xattr restore to use O_NOFOLLOW so attributes are applied to symlink.

TODO: Tests, possible option to switch off mutable/append prior to
restore of existing file similar to rsync. Does not apply attributes
or flags to the top most directory.
2023-10-07 13:55:51 -05:00
0bfab89057 Increase b2 client max file listing count to 10000
Considerable speed improvement with listing large storage.
2023-10-07 13:55:51 -05:00
3468117fe1 Fix exclude_by_attribute feature on POSIX
The exclude by attribute function is broken on non-Darwin POSIX: linux and freebsd.
This is because those xattrs must be prefixed by a legal namespace. The old xattr
library implicitly appended the user namespace to the xattr, but the current
official go pkg does not (which is just as well).

Also fix the test to remove the discordant old xattr dependency and provide
test cases for both darwin and non-darwin POSIX.
2023-10-07 13:55:51 -05:00
b443e05113 Use S3 ListObjectsV2 for listing files
ListObjects has been deprecated since 2016 and ListObjectsV2 with use of
explicit pagination tokens is more performant for large listings as well.

This also mitigates an issue with iDrive E2 where the StartAfter/Marker
is included in the output, leading to duplicate entries. Right now this
causes an exhaustive prune to delete chunks erroneously flagged as
duplicate, destroying the storage.
2023-10-07 13:55:51 -05:00
Gilbert Chen
2549532676 Bump version to 3.2.3 v3.2.3 2023-10-06 22:13:33 -04:00
Gilbert Chen
e99dfea048 Upgrade storj.io/uplink to v1.12.1 to fix an 64 bit alignment issue 2023-10-06 22:12:12 -04:00
Gilbert Chen
50120146df Bump version to 3.2.2 v3.2.2 2023-10-03 22:35:18 -04:00
Gilbert Chen
7bfc0e7d51 Save passwords after a storj storage has been created 2023-10-03 22:33:41 -04:00
Gilbert Chen
fd3bceae19 Bump version to 3.2.1 v3.2.1 2023-10-02 12:30:23 -04:00
Gilbert Chen
7cc1b4222c Update go version to 1.19.13 2023-09-28 23:17:24 -04:00
Gilbert Chen
d92b1734f4 Skip identical entries when listing chunks
The prune command can remove redundant chunks (chunks with the same chunk id
but at different subdirectory level).  However, if the same chunk appears
mutliple times in the listing returned by the storage, it will be treated as
a redundant chunk and thus removed.
2023-09-27 15:31:08 -04:00
Gilbert Chen
4e9d2c4cca Allow two copy-compatible storages to have different compression levels
This is useful for upgrading an existing storage to zstd compression or others.
Chunks need to be decompressed and re-compressed during copy anyway.  Only
the bit-identical option requires the same compression level

Also fix a typo: compatiable -> compatible
2023-09-18 14:44:41 -04:00
gilbertchen
cc482beb95 Merge pull request #653 from gorbak25/fix-compression
Fix compression level check
2023-09-18 10:50:55 -04:00
Grzegorz Uriasz
bf3ea8a83c Fix compression level check 2023-09-11 23:03:34 +02:00