# Rclone : Guide Expert pour la Synchronisation Cloud sur VPS Linux ## Qu'est-ce que Rclone ? Rclone est un outil en ligne de commande open-source permettant de gérer des fichiers sur plus de 70 services de stockage cloud. Souvent qualifié de **"rsync pour le cloud"**, il offre des fonctionnalités avancées de synchronisation, transfert, chiffrement et montage de systèmes de fichiers distants. ### Architecture Interne ``` ┌─────────────────────────────────────────────────────────┐ │ Rclone Core │ │ (Operations Engine) │ ├─────────────────────────────────────────────────────────┤ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ VFS │ │ Crypt │ │ Chunker │ │ │ │ Layer │ │ Layer │ │ Layer │ │ │ │ (Mount │ │ (Client- │ │ (Split │ │ │ │ Cache) │ │ Side) │ │ Files) │ │ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ │ │ │ │ │ └───────────────┴───────────────┘ │ │ │ │ │ ┌────────▼────────┐ │ │ │ Backend │ │ │ │ Abstraction │ │ │ └────────┬────────┘ │ └───────────────────────┼────────────────────────────────┘ │ ┌───────────────┼───────────────┐ │ │ │ ┌───▼───┐ ┌───▼───┐ ┌───▼───┐ │ S3/R2 │ │GDrive │ │ SFTP │ │ B2 │ │OneDrv │ │WebDAV │ └───────┘ └───────┘ └───────┘ ``` ### Capacités Principales ``` ┌──────────────────────────────────────────────┐ │ Fonctionnalités Rclone │ ├──────────────────────────────────────────────┤ │ ✅ Synchronisation bidirectionnelle │ │ ✅ Chiffrement côté client │ │ ✅ Montage FUSE (comme disque local) │ │ ✅ Transfert server-side (pas de download) │ │ ✅ Gestion des versions │ │ ✅ Déduplication │ │ ✅ Filtrage avancé (regex, glob) │ │ ✅ Limitation bande passante │ │ ✅ Reprise automatique │ │ ✅ Vérification d'intégrité (checksum) │ └──────────────────────────────────────────────┘ ``` ### Prérequis Système | Composant | Minimum | Recommandé | VeryCloud | |-----------|---------|------------|-----------| | **RAM** | 512 MB | 2 GB+ | VPS NVMe 4GB | | **CPU** | 1 vCPU | 2+ vCPU | VPS Ryzen | | **Stockage** | 100 MB | 1 GB (cache) | SSD/NVMe | | **Kernel** | 3.10+ | 5.4+ (FUSE3) | Ubuntu 24.04 | | **OS** | Ubuntu 18.04+ | Ubuntu 22.04/24.04 | ✅ Supporté | --- ## Installation Avancée ### Méthode 1 : Script Officiel (Recommandée) **Installation en une ligne** : ```bash curl -fsSL https://rclone.org/install.sh | sudo bash ``` **Vérification** : ```bash rclone version ``` **Sortie attendue** : ``` rclone v1.68.2 - os/version: ubuntu 24.04 (64 bit) - os/kernel: 6.8.0-51-generic (x86_64) - os/type: linux - os/arch: amd64 - go/version: go1.23.4 ``` ### Méthode 2 : Installation Manuelle (Contrôle Total) **Avantages** : - Choix précis de la version - Vérification de signature - Installation sans droits root (optionnel) ```bash # Définir la version souhaitée RCLONE_VERSION="v1.68.2" ARCH="amd64" # ou arm64 pour ARM # Téléchargement cd /tmp curl -LO "https://downloads.rclone.org/${RCLONE_VERSION}/rclone-${RCLONE_VERSION}-linux-${ARCH}.zip" # Extraction unzip rclone-${RCLONE_VERSION}-linux-${ARCH}.zip cd rclone-${RCLONE_VERSION}-linux-${ARCH} # Installation binaire sudo cp rclone /usr/local/bin/ sudo chmod 755 /usr/local/bin/rclone # Installation des pages man sudo mkdir -p /usr/local/share/man/man1 sudo cp rclone.1 /usr/local/share/man/man1/ sudo mandb # Autocomplétion Bash rclone completion bash | sudo tee /etc/bash_completion.d/rclone > /dev/null # Autocomplétion Zsh rclone completion zsh | sudo tee /usr/local/share/zsh/site-functions/_rclone > /dev/null # Nettoyage cd /tmp rm -rf rclone-${RCLONE_VERSION}-linux-${ARCH}* ``` ### Méthode 3 : Compilation depuis les Sources **Pour les utilisateurs avancés** : ```bash # Installer Go 1.21+ sudo apt update sudo apt install -y golang-go git # Clonage git clone https://github.com/rclone/rclone.git cd rclone # Compilation optimisée go build -ldflags "-s -w" -o rclone # Installation sudo mv rclone /usr/local/bin/ sudo chmod +x /usr/local/bin/rclone ``` ### Installation FUSE (Montage) **Requis pour `rclone mount`** : ```bash # Ubuntu/Debian sudo apt update sudo apt install -y fuse3 libfuse3-dev # Activer FUSE pour utilisateurs non-root sudo sed -i 's/#user_allow_other/user_allow_other/' /etc/fuse.conf # Vérification cat /etc/fuse.conf | grep user_allow_other ``` **Sortie attendue** : ``` user_allow_other ``` --- ## Configuration Multi-Provider ### Structure du Fichier de Configuration **Emplacement** : `~/.config/rclone/rclone.conf` **Format** : INI avec sections par remote ``` [nom-du-remote] type = type_de_stockage option1 = valeur1 option2 = valeur2 ``` ### Configuration Google Drive #### Méthode Interactive ```bash rclone config # Menu interactif : # n) New remote # Name: gdrive # Storage: drive (Google Drive) # client_id: (laisser vide ou votre propre OAuth) # client_secret: (laisser vide ou votre propre OAuth) # scope: drive # service_account_file: (laisser vide) # Edit advanced config: n # Use auto config: y (si navigateur disponible) ``` #### Configuration Headless (VPS sans GUI) **Sur votre PC local** : ```bash rclone authorize "drive" ``` **Copier le token généré, puis sur le VPS** : ```bash rclone config # n) New remote # Name: gdrive # Storage: drive # ... (autres options) # Use auto config: n # Coller le token obtenu ``` #### Exemple de Configuration Complète ```ini [gdrive] type = drive client_id = YOUR_CLIENT_ID.apps.googleusercontent.com client_secret = YOUR_CLIENT_SECRET scope = drive token = {"access_token":"ya29.xxx","token_type":"Bearer","refresh_token":"1//xxx","expiry":"2026-01-31T10:00:00Z"} team_drive = root_folder_id = ``` ### Configuration Amazon S3 ```bash rclone config # Name: s3-aws # Storage: s3 (Amazon S3) # Provider: AWS # Get AWS credentials from runtime: n # access_key_id: AKIAIOSFODNN7EXAMPLE # secret_access_key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY # region: eu-west-1 # endpoint: (laisser vide pour AWS) # acl: private # storage_class: STANDARD_IA ``` **Fichier résultant** : ```ini [s3-aws] type = s3 provider = AWS access_key_id = AKIAIOSFODNN7EXAMPLE secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY region = eu-west-1 acl = private storage_class = STANDARD_IA ``` ### Configuration Cloudflare R2 ```ini [s3-r2] type = s3 provider = Cloudflare access_key_id = YOUR_R2_ACCESS_KEY secret_access_key = YOUR_R2_SECRET_KEY endpoint = https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com acl = private no_check_bucket = true ``` ### Configuration Backblaze B2 ```bash rclone config # Name: b2 # Storage: b2 (Backblaze B2) # account: YOUR_APPLICATION_KEY_ID # key: YOUR_APPLICATION_KEY # hard_delete: true (suppression définitive) ``` **Fichier résultant** : ```ini [b2] type = b2 account = YOUR_APPLICATION_KEY_ID key = YOUR_APPLICATION_KEY hard_delete = true ``` ### Configuration SFTP ```ini [sftp-backup] type = sftp host = backup.verycloud.fr user = backupuser port = 22 key_file = ~/.ssh/backup_key shell_type = unix md5sum_command = md5sum sha1sum_command = sha1sum ``` ### Configuration avec Service Account (Google Workspace) **Pour automatisation sans interaction** : 1. **Créer le répertoire** : ```bash mkdir -p ~/.config/rclone/sa ``` 2. **Placer le fichier JSON** : ```bash # Télécharger depuis Google Cloud Console # Placer dans : ~/.config/rclone/sa/service-account.json ``` 3. **Configurer Rclone** : ```ini [gdrive-sa] type = drive scope = drive service_account_file = /home/user/.config/rclone/sa/service-account.json team_drive = 0ABCdefGHIjklMNOpqr ``` ### Vérification de la Configuration ```bash # Lister les remotes configurés rclone listremotes # Tester la connexion rclone lsd gdrive: # Afficher la configuration d'un remote rclone config show gdrive ``` --- ## Commandes Fondamentales ### Syntaxe Générale ``` rclone [options] subcommand [] [flags] ``` **Schéma des opérations** : ``` ┌──────────────┐ ┌──────────────┐ │ Source │ │ Destination │ │ │ │ │ │ /local/ │ ──── rclone ────► │ remote: │ │ remote1: │ sync/copy │ /local/ │ │ │ │ remote2: │ └──────────────┘ └──────────────┘ ``` ### Listing et Navigation ```bash # Lister les remotes configurés rclone listremotes # Lister le contenu (taille uniquement) rclone ls gdrive: rclone ls gdrive:Documents/ # Listing détaillé (taille + date) rclone lsl gdrive: # Lister uniquement les répertoires rclone lsd gdrive: # Arborescence complète rclone tree gdrive:Projects/ --level 3 # Format JSON (pour scripting) rclone lsjson gdrive: --recursive # Recherche de fichiers rclone ls gdrive: --include "*.pdf" --recursive rclone ls gdrive: --include "backup-*.tar.gz" ``` **Exemple de sortie** : ``` 1024 file1.txt 2048 folder/file2.pdf 1048576 archive.zip ``` ### Copie de Fichiers **Schéma copie** : ``` Copie (copy) ──────────── Source : A, B, C Destination : A, B, C, D ↓ Résultat : A, B, C, D (D conservé) ``` ```bash # Copie locale → remote rclone copy /local/path gdrive:backup/ -P # Copie remote → local rclone copy gdrive:Documents/ /local/documents/ -P # Copie entre deux remotes (server-side si supporté) rclone copy gdrive:source/ s3-aws:destination/ -P # Copie d'un seul fichier rclone copyto /local/file.txt gdrive:backup/file.txt # Copie avec limite de bande passante rclone copy /data/ gdrive:backup/ --bwlimit 10M -P ``` ### Déplacement de Fichiers **Schéma move** : ``` Move (move) ─────────── Source : A, B, C → (vide) Destination : D → A, B, C, D ``` ```bash # Déplacement (copie + suppression source) rclone move /local/temp/ gdrive:archive/ -P # Déplacement avec vérification rclone move /old/data/ gdrive:new/ --check-first -P ``` ### Synchronisation **⚠️ ATTENTION : `sync` supprime les fichiers en destination non présents en source !** **Schéma sync** : ``` Sync (sync) ─────────── Source : A, B, C Destination : A, B, D ↓ Résultat : A, B, C (D supprimé !) ``` ```bash # Synchronisation unidirectionnelle (source → destination) rclone sync /local/data/ gdrive:data/ -P # TOUJOURS faire un dry-run d'abord ! rclone sync /local/data/ gdrive:data/ --dry-run # Synchronisation bidirectionnelle (EXPERIMENTAL) rclone bisync /local/data/ gdrive:data/ --resync ``` ### Suppression ```bash # Supprimer un fichier spécifique rclone deletefile gdrive:path/to/file.txt # Supprimer un répertoire et son contenu rclone purge gdrive:old-backup/ # Supprimer uniquement les fichiers (garde les dossiers) rclone delete gdrive:temp/ # Supprimer les dossiers vides rclone rmdirs gdrive: --leave-root # Supprimer les fichiers de plus de 30 jours rclone delete gdrive:logs/ --min-age 30d ``` ### Flags Essentiels | Flag | Description | Exemple | |------|-------------|---------| | `-P, --progress` | Affiche la progression | `rclone copy ... -P` | | `-v, --verbose` | Mode verbeux | `rclone copy ... -v` | | `-n, --dry-run` | Simulation sans modification | `rclone sync ... --dry-run` | | `--transfers N` | Transferts parallèles | `--transfers 8` | | `--checkers N` | Vérificateurs parallèles | `--checkers 16` | | `--bwlimit RATE` | Limite bande passante | `--bwlimit 10M` | | `--exclude PATTERN` | Exclure fichiers | `--exclude "*.tmp"` | | `--include PATTERN` | Inclure uniquement | `--include "*.pdf"` | | `--min-size SIZE` | Taille minimale | `--min-size 1M` | | `--max-size SIZE` | Taille maximale | `--max-size 100M` | | `--min-age DURATION` | Âge minimum | `--min-age 7d` | | `--max-age DURATION` | Âge maximum | `--max-age 30d` | --- ## Filtrage Avancé ### Patterns de Filtrage **Syntaxe** : ``` + pattern # Inclure - pattern # Exclure ``` **Exemple de fichier de filtres** : ```bash cat > /etc/rclone/filters.txt << 'EOF' # Inclusions (processées en premier) + **.pdf + **.docx + **.xlsx + Documents/** + Photos/**/*.jpg # Exclusions - *.tmp - *.log - *.cache - .git/** - node_modules/** - __pycache__/** - .DS_Store - Thumbs.db - desktop.ini # Exclure fichiers > 1Go - **/* + **/*{0..1073741824} EOF ``` **Utilisation** : ```bash rclone sync /data/ gdrive:backup/ \ --filter-from /etc/rclone/filters.txt \ -P ``` ### Filtres en Ligne de Commande ```bash # Inclure uniquement les PDFs rclone copy /docs/ gdrive:backup/ --include "*.pdf" # Exclure les fichiers temporaires rclone sync /data/ gdrive:backup/ --exclude "*.tmp" --exclude "*.log" # Filtres multiples rclone copy /photos/ gdrive:backup/ \ --include "*.jpg" \ --include "*.png" \ --exclude "*thumbnail*" \ --min-size 100K \ --max-size 50M ``` ### Filtrage par Date ```bash # Copier fichiers modifiés dans les 7 derniers jours rclone copy /data/ gdrive:backup/ --max-age 7d -P # Archiver fichiers de plus de 90 jours rclone move /data/ gdrive:archive/ --min-age 90d -P # Supprimer fichiers de plus d'un an rclone delete gdrive:logs/ --min-age 365d ``` --- ## Montage FUSE et Cache ### Concept du Montage FUSE ``` ┌──────────────────────────────────────────────┐ │ Applications Linux │ │ (ls, cp, vim, plex, etc.) │ └──────────────┬───────────────────────────────┘ │ │ Appels système (open, read, write) │ ┌──────────────▼───────────────────────────────┐ │ Rclone FUSE │ │ (Mount + VFS Cache) │ └──────────────┬───────────────────────────────┘ │ │ API Calls (HTTP/S) │ ┌──────────────▼───────────────────────────────┐ │ Cloud Storage │ │ (Google Drive, S3, B2, etc.) │ └──────────────────────────────────────────────┘ ``` ### Montage de Base ```bash # Créer le point de montage sudo mkdir -p /mnt/gdrive sudo chown $USER:$USER /mnt/gdrive # Montage simple rclone mount gdrive: /mnt/gdrive --daemon # Vérification ls /mnt/gdrive/ df -h | grep gdrive ``` ### Montage avec Options Avancées ```bash rclone mount gdrive: /mnt/gdrive \ --daemon \ --allow-other \ --vfs-cache-mode full \ --vfs-cache-max-size 10G \ --vfs-cache-max-age 24h \ --vfs-read-chunk-size 64M \ --vfs-read-chunk-size-limit 1G \ --buffer-size 256M \ --dir-cache-time 72h \ --poll-interval 15s \ --log-file /var/log/rclone/gdrive.log \ --log-level INFO ``` ### Modes de Cache VFS **Comparaison des modes** : | Mode | Lecture | Écriture | Usage | Performance | |------|---------|----------|-------|-------------| | `off` | Streaming | Direct | Vidéos, streaming | Faible, économe | | `minimal` | Streaming | Cache | Upload fichiers | Moyenne | | `writes` | Streaming | Cache jusqu'à upload | Édition occasionnelle | Bonne | | `full` | Cache complet | Cache complet | Usage intensif, apps | Excellente | **Schéma des modes** : ``` Mode OFF ──────── App → FUSE → Cloud (direct, pas de cache) Mode MINIMAL ──────────── App → FUSE → Cache (écriture) → Cloud App → FUSE → Cloud (lecture directe) Mode WRITES ─────────── App → FUSE → Cache → Cloud (après fermeture) App → FUSE → Cloud (lecture directe) Mode FULL ───────── App → FUSE → Cache local ⇄ Cloud (lecture et écriture en cache, sync automatique) ``` ### Service Systemd (Montage Persistant) **Créer l'utilisateur dédié** : ```bash sudo useradd -r -s /usr/sbin/nologin rclone sudo mkdir -p /var/log/rclone /var/cache/rclone sudo chown rclone:rclone /var/log/rclone /var/cache/rclone ``` **Créer le service** : ```bash sudo tee /etc/systemd/system/rclone-gdrive.service << 'EOF' [Unit] Description=Rclone Mount - Google Drive Documentation=https://rclone.org/docs/ After=network-online.target Wants=network-online.target [Service] Type=notify User=rclone Group=rclone ExecStartPre=/bin/mkdir -p /mnt/gdrive ExecStart=/usr/local/bin/rclone mount gdrive: /mnt/gdrive \ --config /home/rclone/.config/rclone/rclone.conf \ --allow-other \ --vfs-cache-mode full \ --vfs-cache-max-size 20G \ --vfs-cache-max-age 72h \ --vfs-read-chunk-size 32M \ --vfs-read-chunk-size-limit 256M \ --buffer-size 128M \ --dir-cache-time 48h \ --poll-interval 30s \ --log-level INFO \ --log-file /var/log/rclone/gdrive.log \ --cache-dir /var/cache/rclone/gdrive ExecStop=/bin/fusermount -uz /mnt/gdrive Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target EOF ``` **Activer le service** : ```bash sudo systemctl daemon-reload sudo systemctl enable rclone-gdrive.service sudo systemctl start rclone-gdrive.service # Vérifier le statut sudo systemctl status rclone-gdrive.service ``` ### Démontage ```bash # Démontage propre fusermount -u /mnt/gdrive # Démontage forcé (si processus bloqué) fusermount -uz /mnt/gdrive # Via systemd sudo systemctl stop rclone-gdrive.service ``` --- ## Chiffrement et Sécurité ### Architecture du Chiffrement ``` ┌──────────────────────────────────────────────┐ │ Fichier Original │ │ document.pdf │ └──────────────┬───────────────────────────────┘ │ │ Chiffrement Client │ (AES-256 / Salsa20) ▼ ┌──────────────────────────────────────────────┐ │ Fichier Chiffré + Nom Obfusqué │ │ q4kp2q8fj3m2nxyz1234567890abcdef │ └──────────────┬───────────────────────────────┘ │ │ Upload ▼ ┌──────────────────────────────────────────────┐ │ Cloud Storage │ │ (fichier illisible par le provider) │ └──────────────────────────────────────────────┘ ``` ### Configuration d'un Remote Chiffré ```bash rclone config # Menu interactif : # n) New remote # Name: gdrive-crypt # Storage: crypt # remote: gdrive:encrypted/ (remote sous-jacent + dossier) # filename_encryption: standard # directory_name_encryption: true # password: (générer un mot de passe fort) # password2: (générer un sel, recommandé) ``` **Fichier résultant** : ```ini [gdrive-crypt] type = crypt remote = gdrive:encrypted/ password = ENCRYPTED_PASSWORD_HASH password2 = ENCRYPTED_SALT_HASH filename_encryption = standard directory_name_encryption = true ``` ### Modes de Chiffrement des Noms | Mode | Noms de fichiers | Noms de dossiers | Exemple | |------|------------------|------------------|---------| | `off` | Clairs | Clairs | `document.pdf` | | `standard` | Chiffrés | Chiffrés | `q4kp2q8fj3m2nxyz...` | | `obfuscate` | Obfusqués | Obfusqués | `yqkpzqFfj3m2nxyz...` | ### Utilisation Transparente ```bash # Les opérations sont identiques rclone copy /sensitive/data/ gdrive-crypt: -P # Côté cloud (via remote non chiffré) rclone ls gdrive:encrypted/ # Output : q4kp2q8fj3m2... (illisible) # Via remote chiffré rclone ls gdrive-crypt: # Output : document.pdf (lisible) ``` ### Sécuriser la Configuration **Chiffrer le fichier de configuration** : ```bash rclone config password # Entrez un mot de passe maître # Le fichier rclone.conf sera chiffré ``` **Utiliser via variable d'environnement** : ```bash export RCLONE_CONFIG_PASS="votre_mot_de_passe_fort" # Ou depuis un fichier secret export RCLONE_CONFIG_PASS=$(cat /run/secrets/rclone_pass) ``` ### Configuration via Variables d'Environnement **Éviter le fichier config** : ```bash # Google Drive export RCLONE_CONFIG_GDRIVE_TYPE=drive export RCLONE_CONFIG_GDRIVE_TOKEN='{"access_token":"..."}' # S3 export RCLONE_CONFIG_S3_TYPE=s3 export RCLONE_CONFIG_S3_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE export RCLONE_CONFIG_S3_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG # Les remotes sont maintenant disponibles sans fichier config rclone ls gdrive: rclone ls s3:bucket/ ``` --- ## Automatisation et Scripting ### Script de Backup Complet **Fichier** : `/usr/local/bin/rclone-backup.sh` ```bash #!/usr/bin/env bash # # rclone-backup.sh - Script de sauvegarde automatisée VeryCloud # Usage: ./rclone-backup.sh [daily|weekly|monthly] # set -euo pipefail # Configuration readonly SCRIPT_NAME=$(basename "$0") readonly LOG_DIR="/var/log/rclone" readonly LOG_FILE="${LOG_DIR}/backup-$(date +%Y%m%d-%H%M%S).log" readonly LOCK_FILE="/var/run/rclone-backup.lock" # Paramètres readonly LOCAL_SOURCE="/var/www" readonly REMOTE_DEST="gdrive-crypt:backups" readonly RETENTION_DAYS=30 readonly BANDWIDTH_LIMIT="50M" readonly MAX_TRANSFERS=4 # Couleurs readonly GREEN='\033[0;32m' readonly RED='\033[0;31m' readonly NC='\033[0m' # Fonctions log() { local level="$1" shift local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo "${timestamp} [${level}] $*" | tee -a "${LOG_FILE}" } cleanup() { rm -f "${LOCK_FILE}" log "INFO" "Verrou libéré" } acquire_lock() { exec 200>"${LOCK_FILE}" if ! flock -n 200; then log "ERROR" "Autre instance en cours" exit 1 fi } perform_backup() { local backup_type="${1:-daily}" local timestamp=$(date +%Y%m%d-%H%M%S) local dest_path="${REMOTE_DEST}/${backup_type}/${timestamp}" log "INFO" "Démarrage backup ${backup_type}" rclone sync "${LOCAL_SOURCE}" "${dest_path}" \ --transfers "${MAX_TRANSFERS}" \ --checkers 8 \ --bwlimit "${BANDWIDTH_LIMIT}" \ --log-file "${LOG_FILE}" \ --log-level INFO \ --stats 1m \ --exclude "*.tmp" \ --exclude "*.log" \ --exclude "cache/**" \ --retries 3 \ --retries-sleep 10s \ -P local exit_code=$? if [ $exit_code -eq 0 ]; then log "INFO" "${GREEN}Backup ${backup_type} OK${NC}" else log "ERROR" "${RED}Backup ${backup_type} FAIL (code: ${exit_code})${NC}" fi return $exit_code } cleanup_old_backups() { log "INFO" "Nettoyage backups > ${RETENTION_DAYS} jours" rclone delete "${REMOTE_DEST}" \ --min-age "${RETENTION_DAYS}d" \ --rmdirs \ --log-file "${LOG_FILE}" log "INFO" "Nettoyage terminé" } main() { local backup_type="${1:-daily}" mkdir -p "${LOG_DIR}" trap cleanup EXIT log "INFO" "=== Démarrage ${SCRIPT_NAME} (${backup_type}) ===" acquire_lock if perform_backup "${backup_type}"; then cleanup_old_backups else exit 1 fi log "INFO" "=== Fin ${SCRIPT_NAME} ===" } main "$@" ``` **Rendre exécutable** : ```bash sudo chmod +x /usr/local/bin/rclone-backup.sh ``` ### Configuration Cron ```bash # Éditer la crontab crontab -e # Backups automatisés # Daily à 2h00 0 2 * * * /usr/local/bin/rclone-backup.sh daily >> /var/log/rclone/cron.log 2>&1 # Weekly le dimanche à 3h00 0 3 * * 0 /usr/local/bin/rclone-backup.sh weekly >> /var/log/rclone/cron.log 2>&1 # Monthly le 1er à 4h00 0 4 1 * * /usr/local/bin/rclone-backup.sh monthly >> /var/log/rclone/cron.log 2>&1 # Nettoyage du cache à 5h00 0 5 * * * rclone cleanup gdrive: --config ~/.config/rclone/rclone.conf ``` ### Timer Systemd (Alternative à Cron) **Service** : ```bash sudo tee /etc/systemd/system/rclone-backup.service << 'EOF' [Unit] Description=Rclone Backup Service After=network-online.target [Service] Type=oneshot User=root ExecStart=/usr/local/bin/rclone-backup.sh daily StandardOutput=journal StandardError=journal EOF ``` **Timer** : ```bash sudo tee /etc/systemd/system/rclone-backup.timer << 'EOF' [Unit] Description=Run Rclone Backup Daily [Timer] OnCalendar=*-*-* 02:00:00 RandomizedDelaySec=300 Persistent=true [Install] WantedBy=timers.target EOF ``` **Activation** : ```bash sudo systemctl daemon-reload sudo systemctl enable --now rclone-backup.timer # Vérifier systemctl list-timers | grep rclone ``` --- ## Optimisation des Performances ### Tuning des Transferts **Configuration haute performance** : ```bash rclone sync /source/ remote:dest/ \ --transfers 16 \ --checkers 32 \ --buffer-size 512M \ --drive-chunk-size 256M \ --fast-list \ --tpslimit 10 \ --tpslimit-burst 20 \ -P ``` ### Paramètres par Provider #### Google Drive ```bash rclone copy /data/ gdrive:backup/ \ --drive-chunk-size 256M \ --drive-upload-cutoff 256M \ --drive-acknowledge-abuse \ --drive-keep-revision-forever=false \ --fast-list \ -P ``` #### Amazon S3 / Cloudflare R2 ```bash rclone copy /data/ s3:bucket/path/ \ --s3-chunk-size 100M \ --s3-upload-cutoff 200M \ --s3-upload-concurrency 8 \ --s3-copy-cutoff 4G \ --fast-list \ -P ``` #### Backblaze B2 ```bash rclone copy /data/ b2:bucket/path/ \ --b2-chunk-size 96M \ --b2-upload-cutoff 200M \ --b2-hard-delete \ --fast-list \ -P ``` ### Gestion de la Bande Passante ```bash # Limite fixe --bwlimit 10M # Limite variable selon l'heure --bwlimit "08:00,512K 18:00,10M 23:00,off" # Limite séparée upload/download --bwlimit "10M:5M" # 10M up, 5M down ``` **Schéma limite variable** : ``` Bande Passante (MB/s) 10 ┤ ┌─────────────┐ │ │ │ 5 ┤ │ │ │ │ │ 0.5 ┤───────────┘ └───────── └───────────────────────────────────> Heure 0h 8h 18h 23h 24h ``` ### Benchmarking ```bash # Test de vitesse complète rclone test speed remote: --transfers 10 # Benchmark mémoire rclone test memory remote:path/ # Mesurer bande passante rclone test bandwidth remote:path/ --time 30s # Test d'un gros fichier time rclone copy /test/1GB.bin remote:test/ -P --stats 1s ``` --- ## Monitoring et Logging ### Configuration des Logs **Niveaux de log** : ```bash --log-level DEBUG # Très verbeux (debug) --log-level INFO # Standard (recommandé) --log-level NOTICE # Important uniquement --log-level ERROR # Erreurs seulement ``` **Sortie fichier** : ```bash rclone copy /data/ remote:backup/ \ --log-file /var/log/rclone/operation.log \ --log-level INFO ``` **Format JSON** (pour parsing) : ```bash --use-json-log ``` ### Statistiques Détaillées ```bash rclone sync /source/ remote:dest/ \ --stats 30s \ --stats-file-name-length 0 \ --stats-log-level NOTICE \ --stats-one-line \ -P ``` ### Logrotate ```bash sudo tee /etc/logrotate.d/rclone << 'EOF' /var/log/rclone/*.log { daily missingok rotate 14 compress delaycompress notifempty create 0640 rclone rclone sharedscripts } EOF ``` --- ## Dépannage Expert ### Problèmes Courants #### Erreur 403 - Rate Limit (Google Drive) **Symptôme** : ``` ERROR : Failed to copy: googleapi: Error 403: User Rate Limit Exceeded ``` **Solutions** : ```bash # 1. Réduire le parallélisme --transfers 2 --checkers 4 # 2. Ajouter des délais --tpslimit 2 --tpslimit-burst 0 # 3. Utiliser votre propre Client ID OAuth # (dans rclone config) ``` #### Token Expiré ```bash # Régénérer le token rclone config reconnect gdrive: # Ou manuellement rclone authorize drive ``` #### Montage FUSE - Permission Denied ```bash # Vérifier /etc/fuse.conf grep user_allow_other /etc/fuse.conf # Décommenter si nécessaire sudo sed -i 's/#user_allow_other/user_allow_other/' /etc/fuse.conf # Remonter avec --allow-other rclone mount remote: /mnt/point --allow-other ``` ### Diagnostic Avancé ```bash # Mode debug complet rclone copy source: dest: -vv --dump headers # Tester la connexion rclone lsd remote: --timeout 30s # Vérifier la config rclone config show remote # Lister les features du backend rclone backend features remote: # Test performance réseau rclone test bandwidth remote: --time 30s ``` --- ## Cas d'Usage Production VeryCloud ### Backup Serveur Web Complet ```bash #!/usr/bin/env bash # backup-webserver.sh - VeryCloud VPS MYSQL_USER="backup" MYSQL_PASS="$(cat /run/secrets/mysql_backup)" BACKUP_DIR="/var/backups/web" REMOTE="b2:verycloud-backups" DATE=$(date +%Y%m%d) mkdir -p "${BACKUP_DIR}/${DATE}" # MySQL dump mysqldump -u${MYSQL_USER} -p${MYSQL_PASS} --all-databases \ | gzip > "${BACKUP_DIR}/${DATE}/mysql-all.sql.gz" # Web files tar -czf "${BACKUP_DIR}/${DATE}/www.tar.gz" -C /var/www . # Configuration tar -czf "${BACKUP_DIR}/${DATE}/etc.tar.gz" \ /etc/nginx /etc/php /etc/mysql # Upload cloud rclone copy "${BACKUP_DIR}/${DATE}" "${REMOTE}/${DATE}/" \ --transfers 4 \ --b2-hard-delete \ -P # Nettoyage local (7 jours) find "${BACKUP_DIR}" -type d -mtime +7 -exec rm -rf {} + # Nettoyage remote (30 jours) rclone delete "${REMOTE}" --min-age 30d --rmdirs ``` ### Media Server avec Rclone Mount **Pour Plex/Jellyfin sur VeryCloud VPS** : ```bash rclone mount gdrive:Media /mnt/media \ --daemon \ --allow-other \ --uid $(id -u plex) \ --gid $(id -g plex) \ --umask 002 \ --vfs-cache-mode full \ --vfs-cache-max-size 100G \ --vfs-cache-max-age 168h \ --vfs-read-chunk-size 128M \ --buffer-size 512M \ --dir-cache-time 168h \ --log-file /var/log/rclone/media.log \ --cache-dir /var/cache/rclone/media ``` --- ## Commandes Rapides ```bash # Vérifier l'espace utilisé rclone size remote:path/ # Nettoyer les fichiers temporaires rclone cleanup remote: # Interface web rclone rcd --rc-web-gui --rc-addr :5572 # Comparer deux remotes rclone check source: dest: --one-way # Calculer checksum rclone hashsum MD5 remote:file.zip ``` --- ## Ressources ### Documentation Officielle - **Site** : https://rclone.org/ - **Docs** : https://rclone.org/docs/ - **Forum** : https://forum.rclone.org/ - **GitHub** : https://github.com/rclone/rclone ### Support VeryCloud | Canal | Disponibilité | |-------|---------------| | **Tickets** | 24/7 | | **Discord** | 600+ membres | | **Documentation** | docs.verycloud.fr | | **Statut** | status.verycloud.fr | --- *Guide rédigé pour VeryCloud SAS • Dernière mise à jour : 30 janvier 2026*