forked from restic/restic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request restic#4990 from m-wild/exclude-cloud-files
backup: allow excluding online-only cloud files
- Loading branch information
Showing
8 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Enhancement: Allow excluding online-only cloud files (e.g. OneDrive) | ||
|
||
Restic treated OneDrive Files On-Demand as though they were regular files | ||
for the purpose of backup which caused issues with VSS, could make backup | ||
incredibly slow (as OneDrive attempted to download files), or could fill | ||
the source disk (e.g. 1TB of files in OneDrive on a 500GB disk). | ||
Restic now allows the user to exclude these files when backing up with | ||
the `--exclude-cloud-files` switch. | ||
|
||
https://github.com/restic/restic/issues/3697 | ||
https://github.com/restic/restic/issues/4935 | ||
https://github.com/restic/restic/pull/4990 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fs_test | ||
|
||
import ( | ||
iofs "io/fs" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/restic/restic/internal/fs" | ||
rtest "github.com/restic/restic/internal/test" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func TestRecallOnDataAccessRealFile(t *testing.T) { | ||
// create a temp file for testing | ||
tempdir := rtest.TempDir(t) | ||
filename := filepath.Join(tempdir, "regular-file") | ||
err := os.WriteFile(filename, []byte("foobar"), 0640) | ||
rtest.OK(t, err) | ||
|
||
fi, err := os.Stat(filename) | ||
rtest.OK(t, err) | ||
|
||
xs := fs.ExtendedStat(fi) | ||
|
||
// ensure we can check attrs without error | ||
recall, err := xs.RecallOnDataAccess() | ||
rtest.Assert(t, err == nil, "err should be nil", err) | ||
rtest.Assert(t, recall == false, "RecallOnDataAccess should be false") | ||
} | ||
|
||
// mockFileInfo implements os.FileInfo for mocking file attributes | ||
type mockFileInfo struct { | ||
FileAttributes uint32 | ||
} | ||
|
||
func (m mockFileInfo) IsDir() bool { | ||
return false | ||
} | ||
func (m mockFileInfo) ModTime() time.Time { | ||
return time.Now() | ||
} | ||
func (m mockFileInfo) Mode() iofs.FileMode { | ||
return 0 | ||
} | ||
func (m mockFileInfo) Name() string { | ||
return "test" | ||
} | ||
func (m mockFileInfo) Size() int64 { | ||
return 0 | ||
} | ||
func (m mockFileInfo) Sys() any { | ||
return &syscall.Win32FileAttributeData{ | ||
FileAttributes: m.FileAttributes, | ||
} | ||
} | ||
|
||
func TestRecallOnDataAccessMockCloudFile(t *testing.T) { | ||
fi := mockFileInfo{ | ||
FileAttributes: windows.FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS, | ||
} | ||
xs := fs.ExtendedStat(fi) | ||
|
||
recall, err := xs.RecallOnDataAccess() | ||
rtest.Assert(t, err == nil, "err should be nil", err) | ||
rtest.Assert(t, recall, "RecallOnDataAccess should be true") | ||
} | ||
|
||
func TestRecallOnDataAccessMockRegularFile(t *testing.T) { | ||
fi := mockFileInfo{ | ||
FileAttributes: windows.FILE_ATTRIBUTE_ARCHIVE, | ||
} | ||
xs := fs.ExtendedStat(fi) | ||
|
||
recall, err := xs.RecallOnDataAccess() | ||
rtest.Assert(t, err == nil, "err should be nil", err) | ||
rtest.Assert(t, recall == false, "RecallOnDataAccess should be false") | ||
} |