mirror of
https://github.com/offen/docker-volume-backup.git
synced 2026-07-11 15:26:17 +02:00
Drive ID needs to be set for shared drives (#784)
* Drive ID needs to be set for shared drives
* Explicitly set corpora value
* Consider Team Drive ID when determining DestinationPath
* Revert "Consider Team Drive ID when determining DestinationPath"
This reverts commit e991fdd46f.
* Update docs
This commit is contained in:
@@ -98,6 +98,7 @@ type Config struct {
|
||||
GoogleDriveImpersonateSubject string `split_words:"true"`
|
||||
GoogleDriveEndpoint string `split_words:"true"`
|
||||
GoogleDriveTokenURL string `split_words:"true"`
|
||||
GoogleDriveTeamDriveID string `split_words:"true"`
|
||||
Timezone string `envconfig:"TZ"`
|
||||
source string
|
||||
additionalEnvVars map[string]string
|
||||
|
||||
@@ -259,6 +259,7 @@ func (s *script) init() error {
|
||||
ImpersonateSubject: s.c.GoogleDriveImpersonateSubject,
|
||||
Endpoint: s.c.GoogleDriveEndpoint,
|
||||
TokenURL: s.c.GoogleDriveTokenURL,
|
||||
TeamDriveID: s.c.GoogleDriveTeamDriveID,
|
||||
}
|
||||
googleDriveBackend, err := googledrive.NewStorageBackend(googleDriveConfig, logFunc)
|
||||
if err != nil {
|
||||
|
||||
@@ -429,6 +429,14 @@ If you need to confirm what the container actually loaded, see [Show loaded conf
|
||||
|
||||
# ---
|
||||
|
||||
# In case you are storing your archives in a "Team Drive", this value needs to be set.
|
||||
# Note that you will still need to set GOOGLE_DRIVE_FOLDER_ID to determine where
|
||||
# archives will be store.
|
||||
|
||||
# GOOGLE_DRIVE_TEAM_DRIVE_ID=""
|
||||
|
||||
# ---
|
||||
|
||||
# The email address of the user to impersonate when accessing Google Drive (domain-wide delegation).
|
||||
# This is required becasue your service account needs to act on behalf of a user in your organization in order to upload files.
|
||||
# How to: https://support.google.com/a/answer/162106
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
|
||||
type googleDriveStorage struct {
|
||||
storage.StorageBackend
|
||||
client *drive.Service
|
||||
client *drive.Service
|
||||
teamDriveID string
|
||||
}
|
||||
|
||||
// Config allows to configure a Google Drive storage backend.
|
||||
@@ -35,6 +36,7 @@ type Config struct {
|
||||
ImpersonateSubject string
|
||||
Endpoint string
|
||||
TokenURL string
|
||||
TeamDriveID string
|
||||
}
|
||||
|
||||
// NewStorageBackend creates and initializes a new Google Drive storage backend.
|
||||
@@ -78,7 +80,8 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error
|
||||
DestinationPath: opts.FolderID,
|
||||
Log: logFunc,
|
||||
},
|
||||
client: srv,
|
||||
client: srv,
|
||||
teamDriveID: opts.TeamDriveID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -135,6 +138,9 @@ func (b *googleDriveStorage) Prune(deadline time.Time, pruningPrefix string) (*s
|
||||
pageToken := ""
|
||||
for {
|
||||
req := b.client.Files.List().Q(query).SupportsAllDrives(true).Fields("files(id, name, createdTime, parents)").PageToken(pageToken)
|
||||
if b.teamDriveID != "" {
|
||||
req = req.DriveId(b.teamDriveID).IncludeItemsFromAllDrives(true).Corpora("drive")
|
||||
}
|
||||
res, err := req.Do()
|
||||
if err != nil {
|
||||
return nil, errwrap.Wrap(err, "listing files")
|
||||
|
||||
Reference in New Issue
Block a user