Работа с S3 через утилиту rclone
Скачиваем бесплатную утилиту rclone для Windows и распаковываем ее в
C:\rclone-v1.65.0-windows-amd64
Конфигурируем rclone в PowerShell
C:\rclone-v1.65.0-windows-amd64\rclone.exe config
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
Enter name for new remote.
name> s3-adman
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, DigitalOcean, Dreamhost, GCS, HuaweiOBS, IBMCOS, IDrive, IONOS, LyveCloud, Leviia, Liara, Linode, Minio, Netease, Petabox, RackCorp, Rclone, Scaleway, SeaweedFS, StackPath, Storj, Synology, TencentCOS, Wasabi, Qiniu and others
\ (s3)
Storage> 5
Option provider.
Choose your S3 provider.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
31 / Any other S3 compatible provider
\ (Other)
provider> 31
Option env_auth.
Get AWS credentials from runtime (environment variables or EC2/ECS meta data if no env vars).
Only applies if access_key_id and secret_access_key is blank.
Choose a number from below, or type in your own boolean value (true or false).
Press Enter for the default (false).
1 / Enter AWS credentials in the next step.
\ (false)
2 / Get AWS credentials from the environment (env vars or IAM).
\ (true)
env_auth> 1
Option access_key_id.
AWS Access Key ID.
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
access_key_id> ваш access_key_id
Option secret_access_key.
AWS Secret Access Key (password).
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
secret_access_key> ваш secret_access_key
Option region.
Region to connect to.
Leave blank if you are using an S3 clone and you don't have a region.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
/ Use this if unsure.
1 | Will use v4 signatures and an empty region.
\ ()
/ Use this only if v4 signatures don't work.
2 | E.g. pre Jewel/v10 CEPH.
\ (other-v2-signature)
region>
Option endpoint.
Endpoint for S3 API.
Required when using an S3 clone.
Enter a value. Press Enter to leave empty.
endpoint> https://s3.adman.com
Option location_constraint.
Location constraint - must be set to match the Region.
Leave blank if not sure. Used when creating buckets only.
Enter a value. Press Enter to leave empty.
location_constraint>
Option acl.
Canned ACL used when creating buckets and storing or copying objects.
This ACL is used for creating objects and if bucket_acl isn't set, for creating buckets too.
For more info visit https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
Note that this ACL is applied when server-side copying objects as S3
doesn't copy the ACL from the source but rather writes a fresh one.
If the acl is an empty string then no X-Amz-Acl: header is added and
the default (private) will be used.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
/ Both the object owner and the bucket owner get FULL_CONTROL over the object.
6 | If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
\ (bucket-owner-full-control)
acl> 6
Edit advanced config?
y) Yes
n) No (default)
y/n> n
Configuration complete.
Options:
- type: s3
- provider: Other
- access_key_id: ваш access_key_id
- secret_access_key: ваш secret_access_key
- endpoint: https://s3.adman.com
- acl: bucket-owner-full-control
Keep this "s3-adman" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
s3-adman s3
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
Создаем бакет
C:\rclone-v1.65.0-windows-amd64\rclone.exe mkdir s3-adman:new-buket
Загрузить объкт в бакет
C:\rclone-v1.65.0-windows-amd64\rclone.exe copy file.txt s3-adman:new-buket
Посмотреть объекты в бакете
C:\rclone-v1.65.0-windows-amd64\rclone.exe ls s3-adman:new-buket
Удалить объект из бакета
C:\rclone-v1.65.0-windows-amd64\rclone.exe deletefile s3-adman:new-buket/file.txt
Синхронизация файлов на локальной машине с файлами в хранилище
C:\rclone-v1.65.0-windows-amd64\rclone.exe sync s3-adman:new-buket каталог_на_локальной_машине
Синхронизация файлов в хранилище с файлами на локальной машине
C:\rclone-v1.65.0-windows-amd64\rclone.exe s3-adman:new-buket sync каталог_на_локальной_машине
Более подробный список команд можно найти в официальной документации.
Монтирование бакета через WinFsp
Чтобы смонтировать контейнер объектного хранилища через rclone, скачиваем и устанавливаем бесплатную утилиту WinFsp.
Возвращаемся в консоль PowerShell и монтируем контейнер через команду:
C:\rclone-v1.65.0-windows-amd64\rclone.exe mount s3-adman:new-buket S: --vfs-cache-mode full
Автоматизируем процесс монтирования бакета
После перезагрузки сервера необходимо будет заново монтировать контейнер как диск. Чтобы не делать это каждый раз, можно автоматизировать запуск rclone.
Создадим исполняемый файл для запуска rclone и переместим его в автозагрузку.
Создаем файл
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\s3disk.cmd
Прописываем в нем команду:
C:\rclone-v1.65.0-windows-amd64\rclone.exe mount s3-adman:new-buket S: --vfs-cache-mode full