237 lines
7.4 KiB
Markdown
237 lines
7.4 KiB
Markdown
1.- Instalar `rclone` en el servidor (si el servidor no tiene interfaz gráfica también instalalo en tu PC o laptop )
|
|
|
|
```bash
|
|
sudo apt install rclone
|
|
```
|
|
|
|
2.- Para poder usar la herramienta y mandar archivos al servidor debemos hacer la configuración inicial mediante el comando:
|
|
```bash
|
|
rclone config
|
|
```
|
|
|
|
Primero debemos crear un repositorio remoto, para ello la herramienta nos hará una serie de preguntas y en algunos casos nos dará opciones, en la consola deberás ingresar cada una de las opciones seguida de la tecla enter:
|
|
|
|
2.1.- La primera vez debemos crear nuestro primer remoto, así que ingresa la letra **n** y **enter**:
|
|
```bash
|
|
No remotes found, make a new one?
|
|
n) New remote
|
|
s) Set configuration password
|
|
q) Quit config
|
|
n/s/q> n
|
|
```
|
|
|
|
2.2.- Nombre de nuevo remoto (no dejes espacios, mejor usa guion bajo):
|
|
```bash
|
|
Enter name for new remote.
|
|
name> db_backups
|
|
```
|
|
|
|
2.3.- Selección de la opción 18, es la opción de Google Drive
|
|
```bash
|
|
Option Storage.
|
|
Type of storage to configure.
|
|
Choose a number from below, or type in your own value.
|
|
|
|
18 / Google Drive
|
|
\ (drive)
|
|
|
|
Storage> 18
|
|
```
|
|
|
|
2.4.- Te pedirá tu id de cliente de Google pero si no lo tienes solo da enter:
|
|
```bash
|
|
Option client_id.
|
|
Google Application Client Id
|
|
Setting your own is recommended.
|
|
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
|
|
If you leave this blank, it will use an internal key which is low performance.
|
|
Enter a value. Press Enter to leave empty.
|
|
client_id>
|
|
```
|
|
|
|
2.5.- Solicitará tu clave de OAuth pero lo puedes dejar vacío, solo da enter:
|
|
```bash
|
|
Option client_secret.
|
|
OAuth Client Secret.
|
|
Leave blank normally.
|
|
Enter a value. Press Enter to leave empty.
|
|
client_secret>
|
|
```
|
|
|
|
2.6.- Te pedirá el tipo de acceso que le darás a Drive, para esta caso yo elegiré la 1 que es acceso total a archivos.
|
|
|
|
```bash
|
|
Option scope.
|
|
Scope that rclone should use when requesting access from drive.
|
|
Choose a number from below, or type in your own value.
|
|
Press Enter to leave empty.
|
|
1 / Full access all files, excluding Application Data Folder.
|
|
\ (drive)
|
|
2 / Read-only access to file metadata and file contents.
|
|
\ (drive.readonly)
|
|
/ Access to files created by rclone only.
|
|
3 | These are visible in the drive website.
|
|
| File authorization is revoked when the user deauthorizes the app.
|
|
\ (drive.file)
|
|
/ Allows read and write access to the Application Data folder.
|
|
4 | This is not visible in the drive website.
|
|
\ (drive.appfolder)
|
|
/ Allows read-only access to file metadata but
|
|
5 | does not allow any access to read or download file content.
|
|
\ (drive.metadata.readonly)
|
|
scope> 1
|
|
```
|
|
|
|
2.7.- Te pedirá la ruta de las credenciales en formato JSON pero lo puedes dejar en blanco y solo dar enter:
|
|
```bash
|
|
Option service_account_file.
|
|
Service Account Credentials JSON file path.
|
|
Leave blank normally.
|
|
Needed only if you want use SA instead of interactive login.
|
|
Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
|
|
Enter a value. Press Enter to leave empty.
|
|
service_account_file>
|
|
```
|
|
|
|
2.8- Preguntará si quieres editar la configuración avanzada, la opción es no (n):
|
|
```bash
|
|
Edit advanced config?
|
|
y) Yes
|
|
n) No (default)
|
|
y/n> n
|
|
```
|
|
|
|
2.9.- Te preguntara si quieres usar el método de configuración automática, pero **ingresa que no, ya que usa una UI y el servidor no tiene interfaz gráfica**.
|
|
|
|
```bash
|
|
Use auto config?
|
|
* Say Y if not sure
|
|
* Say N if you are working on a remote or headless machine
|
|
|
|
y) Yes (default)
|
|
n) No
|
|
y/n> n
|
|
```
|
|
|
|
2.9.1.- Del comando anterior en consola te mostrará un mensaje como este:
|
|
```bash
|
|
Option config_token.
|
|
For this to work, you will need rclone available on a machine that has
|
|
a web browser available.
|
|
For more help and alternate methods see: https://rclone.org/remote_setup/
|
|
Execute the following on the machine with the web browser (same rclone
|
|
version recommended):
|
|
rclone authorize "drive" "ayXzY01uSSI8ImRiaXZlIm0"
|
|
Then paste the result.
|
|
Enter a value.
|
|
config_token>
|
|
```
|
|
|
|
|
|
En tu computadora local, **NO EN EL SERVIDOR**, deberás abrir una terminal (previamente debiste instalar rclone en esa maquina), y pegar el comando que te da la terminal del servidor que en este caso es:
|
|
```bash
|
|
rclone authorize "drive" "ayXzY01uSSI8ImRiaXZlIm0"
|
|
```
|
|
|
|
De ese comando verás que te despliega la consola una respuesta como esta:
|
|
```bash
|
|
2025/06/03 13:12:35 NOTICE: Config file "/home/dave/.config/rclone/rclone.conf" not found - using defaults
|
|
2025/06/03 13:12:35 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=VQQBIGPyiSNLYReNNPIXmj
|
|
2025/06/03 13:12:35 NOTICE: Log in and authorize rclone for access
|
|
2025/06/03 13:12:35 NOTICE: Waiting for code...
|
|
```
|
|
|
|
En la segunda línea del mensaje, copia y pega en tu navegador la URL que aparece despues de link, en este caso es: http://127.0.0.1:53682/auth?state=VQQBIGPyiSNLYReNNPIXmj
|
|
|
|
En tu navegador te aparecerán las cuentas de gmail, selecciona la cuenta de gmail que corresponde al DRIVE que le darás acceso a rclone, de forma inmediata el navegador te dará un mensaje de **SUCCESS** y debes regresar a tu consola de tu maquina local y te dará un hash largo similar a este:
|
|
```bash
|
|
Paste the following into your remote machine --->
|
|
eyJ0b2tlbiI6IntcImFjY2Vzc19....[muchos-caracteres]....NjowMFwifSJ9
|
|
<---End paste
|
|
```
|
|
Copia lo que esta entre las flechas (---> hash <---) y pégalo en la terminal de tu servidor VPS.
|
|
|
|
2.10.- Te preguntará que si es un drive compartido, en este caso es no:
|
|
|
|
```bash
|
|
Configure this as a Shared Drive (Team Drive)?
|
|
|
|
y) Yes
|
|
n) No (default)
|
|
y/n> n
|
|
```
|
|
|
|
2.11.- Finalmente te hará la pregunta de si quieres mantener la configuración hecha, debes ingresar la y:
|
|
```bash
|
|
Configuration complete.
|
|
Options:
|
|
- type: drive
|
|
- scope: drive
|
|
- token: {"access_token":"datos-de-tu-token-de-acceso","token_type":"tu-tipo-de-token","refresh_token":"hash-del-token","expiry":"time-stamp-expiracion"}
|
|
- team_drive:
|
|
Keep this "db_backups" remote?
|
|
y) Yes this is OK (default)
|
|
e) Edit this remote
|
|
d) Delete this remote
|
|
y/e/d> y
|
|
```
|
|
|
|
Listo, tu configuración ya esta hecha, ahora solo debes salir de rclone ingresando la letra `q` seguida del enter, y en
|
|
|
|
### Subir carpeta con `rclone copy`
|
|
|
|
Este comando copia los archivos de origen a destino, sin borrar nada en destino.
|
|
|
|
```bash
|
|
rclone copy /ruta/local/de/la/carpeta formha_db_backups:/carpeta-en-drive
|
|
```
|
|
|
|
rclone copy /home/dix/backups-db/ formha_db_backups:/formha-db-backups
|
|
|
|
|
|
* `/ruta/local/de/la/carpeta` → la carpeta en tu VPS que quieres subir.
|
|
* `formha_db_backups:/carpeta-en-drive` → la carpeta en tu Google Drive (se creará si no existe).
|
|
|
|
Ejemplo:
|
|
|
|
```bash
|
|
rclone copy /home/dix/backups formha_db_backups:/backups-vps -p --v
|
|
```
|
|
|
|
Esto copiará todo el contenido de `/home/dix/backups` a la carpeta `backups-vps` en Google Drive.
|
|
|
|
---
|
|
|
|
### Subir carpeta con `rclone sync`
|
|
|
|
Si quieres que la carpeta en Google Drive **quede idéntica** a la local (borra archivos en Drive que no estén en local):
|
|
|
|
```bash
|
|
rclone sync /ruta/local/de/la/carpeta formha_db_backups:/carpeta-en-drive
|
|
```
|
|
|
|
Ten cuidado con `sync` porque puede eliminar archivos en Drive.
|
|
|
|
---
|
|
|
|
### Otros tips útiles
|
|
|
|
* Para ver el contenido en Drive:
|
|
|
|
```bash
|
|
rclone ls formha_db_backups:/carpeta-en-drive
|
|
```
|
|
|
|
* Para hacer dry-run (simular qué pasaría sin cambios reales):
|
|
|
|
```bash
|
|
rclone copy --dry-run /home/dix/backups formha_db_backups:/backups-vps
|
|
```
|
|
|
|
---
|
|
|
|
¿Quieres que te ayude con un script automático o programación de backups?
|
|
|
|
|
|
|