backup_uploader
is a tool for synchronizing files between a local directory and Google Drive. It allows you to upload and update files on Google Drive while ensuring that files are compared using hash values to avoid duplication and reduce unnecessary traffic.
- Synchronize a local directory with Google Drive (
to_drive
). - Synchronize Google Drive with a local directory (
from_drive
). - Automatically create missing folders on Google Drive when uploading.
- Compare files based on MD5 hash values.
- Update only files that have been modified.
- Support for debug mode with detailed output (
-vv
or--debug
). - Upload a single file directly to Google Drive with the
-upload_file
flag.
-
Install Go (https://golang.org/doc/install).
-
Clone the repository:
git clone https://github.com/yourusername/backup_uploader.git cd backup_uploader
-
Build the executable:
go build -o backup_uploader
-c
: Path to thecredentials.json
file for Google API (default:~/.backup_uploader/google/credentials.json
).-sync_folder
: Path to the local directory to sync.-folder_path
: Path to the target folder on Google Drive.-drive_id
: Google Drive ID (for Shared Drives, optional).-file_mask
: File mask to filter files for syncing (e.g.,*.txt
).-mkdir
: Flag to create directories on Google Drive if they do not exist.-direction
: Sync direction (to_drive
orfrom_drive
).-vv
,--debug
: Enable verbose output (debug mode).-upload_file
: Path to a single file to upload to Google Drive.
-
Synchronize a local directory with Google Drive:
./backup_uploader -c path/to/credentials.json -sync_folder /path/to/local/folder -folder_path "TargetFolder" -drive_id YOUR_DRIVE_ID -mkdir -direction to_drive -file_mask '*.txt' -vv
-
Synchronize Google Drive with a local directory:
./backup_uploader -c path/to/credentials.json -sync_folder /path/to/local/folder -folder_path "TargetFolder" -drive_id YOUR_DRIVE_ID -mkdir -direction from_drive -file_mask '*.txt' -vv
-
Upload a single file to Google Drive:
./backup_uploader -c path/to/credentials.json -upload_file /path/to/file.txt -folder_path "TargetFolder" -vv
When running the script with the -vv
or --debug
flag, detailed debugging information is output, including:
- A list of files and their hashes on Google Drive.
- A list of local files and their hashes.
- Messages about which files were updated, skipped, or uploaded.
To build the executable for different platforms, you can use the following commands:
-
Linux:
GOOS=linux GOARCH=amd64 go build -o backup_uploader_linux
-
Windows:
GOOS=windows GOARCH=amd64 go build -o backup_uploader_windows.exe
-
macOS (Intel):
GOOS=darwin GOARCH=amd64 go build -o backup_uploader_mac
-
macOS (Apple Silicon):
GOOS=darwin GOARCH=arm64 go build -o backup_uploader_mac_arm64
If you would like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a Pull Request.
Please make sure to update tests as appropriate and follow the code style guidelines.
To test the script's functionality, you can use the following command:
go test -v
This project is licensed under the MIT License - see the LICENSE file for details.