Истории успеха наших клиентов — лучшие проекты
Вход/ Регистрация
На главную
25eb9e0a-a5a8-472a-ace7-940b8bd2adf0
Облачные сервисы

Rclone

Rclone — утилита командной строки для синхронизации файлов и каталогов между локальной машиной и облачным хранилищем.

Установка rclone

Дистрибутивы программы для разных архитектур и ОС можно скачать с сайта разработчика. Инструкции по установке также есть на официальном сайте.

Для Windows достаточно скачать и запустить rclone.exe через командную строку.

Настройка rclone

Для настройки rclone для работы с нашим объектным хранилищем S3 необходимо создать в каталоге .config/rclone в корне домашней директории файл rclone.conf со следующим содержимым:

    
[timeweb-cloud] type = s3 provider = Other env_auth = false access_key_id = <S3 Access Key> secret_access_key = <S3 Secret Access Key> endpoint = https://s3.twcstorage.ru

Значения S3 Access Key и S3 Secret Access Key можно найти во вкладке «Дашборд» в панели управления бакетом.

Selection 252

Либо можно воспользоваться мастером настройки, который сформирует аналогичный файл.

Для запуска мастера настройки в Linux и macOS выполните команду:

    
rclone config

Для запуска в Windows используйте:

    
.\rclone.exe config

Пример выполнения настройки через мастер:

Нажмите n для создания новой конфигурации. Укажите имя конфигурации, по которому в дальнейшем будет выполняться обращение к кластеру:

    
No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n name> timeweb-cloud

Укажите номер, соответствующий значению «Amazon S3 Compliant Storage Provider». В данном случае — 4:

    
Type of storage to configure. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / 1Fichier \ "fichier" 2 / Alias for an existing remote \ "alias" 3 / Amazon Drive \ "amazon cloud drive" 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc) \ "s3" ... 30 / Yandex Disk \ "yandex" 31 / http Connection \ "http" 32 / premiumize.me \ "premiumizeme" Storage> 4

Выберите номер, соответствующий «Any other S3 compatible provider». В данном случае — 13:

    
Choose your S3 provider. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / Amazon Web Services (AWS) S3 \ "AWS" 2 / Alibaba Cloud Object Storage System (OSS) formerly Aliyun \ "Alibaba" 3 / Ceph Object Storage \ "Ceph" ... 11 / Tencent Cloud Object Storage (COS) \ "TencentCOS" 12 / Wasabi Object Storage \ "Wasabi" 13 / Any other S3 compatible provider \ "Other" provider> 13

Укажите значение false для ручной настройки данных подключения:

    
Only applies if access_key_id and secret_access_key is blank. Enter a boolean value (true or false). Press Enter for the default ("false"). Choose a number from below, or type in your own value 1 / Enter AWS credentials in the next step \ "false" 2 / Get AWS credentials from the environment (env vars or IAM) \ "true" env_auth> false

Вместо <S3 Access Key> укажите значение S3 Access Key из панели управления:

    
AWS Access Key ID. Leave blank for anonymous access or runtime credentials. Enter a string value. Press Enter for the default (""). access_key_id> <S3 Access Key>

Вместо <S3 Secret Access Key> укажите значение S3 Secret Access Key из панели управления:

    
AWS Secret Access Key (password) Leave blank for anonymous access or runtime credentials. Enter a string value. Press Enter for the default (""). secret_access_key> <S3 Secret Access Key>

Укажите ru-1:

    
Region to connect to. Leave blank if you are using an S3 clone and you don't have a region. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / Use this if unsure. Will use v4 signatures and an empty region. \ "" 2 / Use this only if v4 signatures don't work, eg pre Jewel/v10 CEPH. \ "other-v2-signature" region> ru-1

В качестве эндпойнта укажите https://s3.twcstorage.ru:

    
Endpoint for S3 API. Required when using an S3 clone. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value endpoint> https://s3.twcstorage.ru

Нажмите «Enter»:

    
Location constraint - must be set to match the Region. Leave blank if not sure. Used when creating buckets only. Enter a string value. Press Enter for the default (""). location_constraint>

Нажмите «Enter»:

    
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. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / Owner gets FULL_CONTROL. No one else has access rights (default). \ "private" 2 / Owner gets FULL_CONTROL. The AllUsers group gets READ access. \ "public-read" / Owner gets FULL_CONTROL. The AllUsers group gets READ and WRITE access. 3 | Granting this on a bucket is generally not recommended. \ "public-read-write" 4 / Owner gets FULL_CONTROL. The AuthenticatedUsers group gets READ access. \ "authenticated-read" / Object owner gets FULL_CONTROL. Bucket owner gets READ access. 5 | If you specify this canned ACL when creating a bucket, Amazon S3 ignores it. \ "bucket-owner-read" / 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>

Укажите n, чтобы не редактировать конфигурацию:

    
Edit advanced config? (y/n) y) Yes n) No y/n> n

Проверьте конфигурацию и подтвердите, что все хорошо, нажав y:

    
Remote config -------------------- [timeweb-cloud] provider = Other env_auth = false access_key_id = <S3 Access Key> secret_access_key = <S3 Secret Access Key> region = ru-1 endpoint = https://s3.twcstorage.ru -------------------- y) Yes this is OK e) Edit this remote d) Delete this remote y/e/d> y

Нажмите q для выхода из мастера настройки:

    
Current remotes: Name Type ==== ==== timeweb-cloud 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

Если при настройке через мастер возникнет ошибка, попробуйте выполнить настройку заново, но без указания региона (ru-1).

Команды для работы с хранилищем

Полный список поддерживаемых команд смотрите в документации rclone.

В качестве хоста указывается имя хранилища, заданное в конфигурационном файле rclone.conf. Так, в нашем примере в начале статьи было настроено хранилище с именем timeweb-cloud.

Просмотр списка бакетов

    
rclone lsd <имя хоста>:

Например:

    
rclone lsd timeweb-cloud:        -1 2021-12-10 11:34:51     -1 1d65c254-17ab-4b22-b262-1111fc006937       -1 2022-01-13 10:05:47     -1 3b24945b-d373-4713-89ec-3dece346c7b3        -1 2022-01-14 12:31:36     -1 bbf30ad7-8872-40fc-8d41-54537d894b7f

Получение списка файлов в бакете

    
rclone ls <имя хоста>:<имя бакета>

Например:

    
rclone ls timeweb-cloud:3b24945b-d373-4713-89ec-3dece346c7b3     13 test.txt     13 test1.txt

Загрузка файла в бакет

    
rclone -P copy <имя файла> <имя хоста>:<имя бакета>

Например:

    
rclone -P copy test5.txt timeweb-cloud:3b24945b-d373-4713-89ec-3dece346c7b3

Удаление файла в бакете

    
rclone delete <имя хоста>:<имя бакета>/<имя файла>

Например:

    
rclone delete timeweb-cloud:3b24945b-d373-4713-89ec-3dece346c7b3/test5.txt

Копирование файлов из бакета в бакет

    
rclone copyto -vP --log-file=rclone_<имя отдающего бакета>.log --transfers=256 <имя отдающего хоста>:<имя отдающего бакета> <имя принимающего хоста>:<имя принимающего бакета>

Синхронизация файлов между бакетом и локальной директорией

    
rclone -P sync timeweb-cloud:3b24945b-d373-4713-89ec-3dece346c7b3 /root/test

Для синхронизации в обратном направлении поменяйте аргументы местами.

Была ли статья полезна?
Ваша оценка очень важна
Пока нет комментариев