4.9 KiB
4.9 KiB
Sincronización R2 con rclone
Configuración de sincronización bidireccional entre carpeta local y Cloudflare R2.
Requisitos
- rclone instalado
- Credenciales R2 (Access Key + Secret)
- macOS con launchd o Linux con systemd
Instalación rclone
macOS
brew install rclone
Linux
curl https://rclone.org/install.sh | sudo bash
Configuración
1. Crear archivo de configuración
mkdir -p ~/.config/rclone
2. Configurar remote R2
~/.config/rclone/rclone.conf:
[r2-architect]
type = s3
provider = Cloudflare
access_key_id = {ACCESS_KEY}
secret_access_key = {SECRET_KEY}
endpoint = https://7dedae6030f5554d99d37e98a5232996.r2.cloudflarestorage.com
acl = private
3. Verificar conexión
# Listar contenido del bucket
rclone lsf r2-architect:architect/
# Con verbose para debug
rclone ls r2-architect:architect/ -vv
Sincronización
Sync unidireccional (R2 → Local)
rclone sync r2-architect:architect/ "/path/to/local/folder/" --progress
Sync unidireccional (Local → R2)
rclone sync "/path/to/local/folder/" r2-architect:architect/ --progress
Bisync bidireccional
# Primera vez: inicializar con --resync
rclone bisync "/path/to/local/folder/" r2-architect:architect/ --resync --verbose
# Ejecuciones posteriores
rclone bisync "/path/to/local/folder/" r2-architect:architect/ --verbose
Automatización
macOS (launchd)
~/Library/LaunchAgents/com.rclone.r2-sync.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.rclone.r2-sync</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/rclone</string>
<string>bisync</string>
<string>/Users/{user}/R2 Folder/</string>
<string>r2-architect:architect/</string>
<string>--verbose</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>StandardOutPath</key>
<string>/Users/{user}/Library/Logs/rclone-r2-sync.log</string>
<key>StandardErrorPath</key>
<string>/Users/{user}/Library/Logs/rclone-r2-sync.log</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Comandos launchd:
# Cargar servicio
launchctl load ~/Library/LaunchAgents/com.rclone.r2-sync.plist
# Ver estado
launchctl list | grep r2-sync
# Detener
launchctl unload ~/Library/LaunchAgents/com.rclone.r2-sync.plist
Linux (systemd)
~/.config/systemd/user/rclone-r2-sync.service:
[Unit]
Description=Rclone R2 Bisync
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/rclone bisync /home/{user}/R2/ r2-architect:architect/ --verbose
~/.config/systemd/user/rclone-r2-sync.timer:
[Unit]
Description=Run rclone R2 sync every 5 minutes
[Timer]
OnBootSec=1min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target
Comandos systemd:
# Habilitar
systemctl --user enable rclone-r2-sync.timer
systemctl --user start rclone-r2-sync.timer
# Ver estado
systemctl --user status rclone-r2-sync.timer
# Ejecutar manualmente
systemctl --user start rclone-r2-sync.service
Buckets R2 Disponibles
| Bucket | Uso | Credenciales |
|---|---|---|
| architect | Backups, configs, APKs | Token: architect-sync |
| hst | Imágenes HST | Token: locker-full-access |
| deck | Archivos personales | Token: locker-full-access |
| corp | Documentos empresariales | Token: locker-full-access |
| locker | General/temporal | Token: locker-full-access |
Tokens R2
locker-full-access (todos los buckets)
Endpoint: https://7dedae6030f5554d99d37e98a5232996.r2.cloudflarestorage.com
Access Key: ecddc771824c3cb3417d9451780db3d2
Secret Key: [ver creds_locker en PostgreSQL]
architect-sync (solo bucket architect)
Access Key: 55125dca442b0f3517d194a5bc0502b8
Secret Key: [ver creds_locker.r2_architect_token en PostgreSQL]
Comandos útiles
# Ver logs en tiempo real
tail -f ~/Library/Logs/rclone-r2-sync.log
# Sync manual inmediato
rclone bisync "/path/to/folder/" r2-architect:architect/ --verbose
# Ver diferencias sin sincronizar
rclone check "/path/to/folder/" r2-architect:architect/
# Listar con tamaños
rclone ls r2-architect:architect/
# Subir archivo específico
rclone copy archivo.txt r2-architect:architect/path/
# Descargar archivo
rclone copy r2-architect:architect/path/archivo.txt ./
Configuración cliente local
Ejemplo configurado en Mac (pablotzr):
| Componente | Valor |
|---|---|
| Carpeta local | /Users/pablotzr/Architect R2/ |
| Bucket R2 | architect |
| Sync | Bidireccional (bisync) |
| Frecuencia | Cada 5 minutos |
| Servicio | com.rclone.r2-architect-sync |
| Logs | ~/Library/Logs/rclone-r2-sync.log |
Creado: 2024-12-24