Cuando necesitas desde Ubuntu acceder a tu cuenta o cuentas de Google Drive, hay diferentes manaras de hacerlo. Después de mucho buscar está es la mejor manera que he visto de realizarlo.
Para sincronizar desde Ubuntu tu Google Drive debes realizar los siguientes pasos:
1.- Crear directorio para el script de monitoreo
1 |
mkdir ~/bin |
Compruebo que a añadido a PATH esta carpeta ejecutando echo $PATH
2.- Crear carpeta local a sincronizar
1 |
mkdir ~/Drive |
3.- Instalamos grive
En debian:
1 |
$ sudo apt-get install grive |
En Ubuntu:
1 2 3 |
$ sudo add-apt-repository ppa:nilarimogard/webupd8 $ apt-get update $ apt-get install grive |
Una vez instalado. Autentificados en nuestro navegador con nuestra cuenta de Google, ejecutamos:
1 |
cd ~/Drive && grive -a |
Pondrá una URL en el terminal. Al pegar esa URL nos dirá si queremos dar permisos a grive para acceder a Drive. Aceptamos y nos dara un codigo que es el que debemos pegar en el terminal.
Así ya estamos autentificados en nuestro Drive.
4.- Instalar inotify-tools
Es necesario instalar este paquete para crear las sincronizaciones automaticas:
1 |
$ sudo apt-get install inotify-tools |
5.- Ahora crearemos un script que monitorize la carpeta local para detectar cualquier cambio (Script gracias a Peter Österberg, 2012):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/bash # Google Drive Grive script that syncs your Google Drive folder on change # This functionality is currently missing in Grive and there are still no # official Google Drive app for Linux coming from Google. # # This script will only detect local changes and trigger a sync. Remote # changes will go undetected and are probably still best sync on a periodic # basis via cron. # # Kudos to Nestal Wan for writing the excellent Grive software # Also thanks to Google for lending some free disk space to me # # Peter Österberg, 2012 GRIVE_COMMAND_WITH_PATH=/usr/bin/grive # Path to your grive binary, change to match your system GDRIVE_PATH=~/Drive # Path to the folder that you want to be synced TIMEOUT=300 # Timeout time in seconds, for periodic syncs. Nicely pointed out by ivanmacx while true do inotifywait -t $TIMEOUT -e modify -e move -e create -e delete -r $GDRIVE_PATH cd $GDRIVE_PATH && $GRIVE_COMMAND_WITH_PATH done |
6.- Damos permiso de ejecución a nuestro script
1 |
$ chmod +x grive.sh |
En mi caso el script esta en ~/bin
7.- Ponemos el script para que sea ejecutado al arranque
En mi caso que es en Ubuntu unicamente hay que buscar «aplicaciones al inicio».
8.- Creamos el cron que ejecutara el script cada X tiempo
1 |
$ crontab -e |
y escribimos la línea :
1 |
*/10 * * * * cd "$HOME"/Drive && grive > /tmp/GRIVE_LOG |
Esto hace que se ejecute cada 10 minutos se detecte si ha habido cambios en el servidor remoto. Y lo mandamos a un archivo temporal.
Tambien podríamos mandarlo a null:
1 |
*/10 * * * * cd "$HOME/Drive" && grive >/dev/null 2>&1 |
Nota: Si hay muchos archivos o carpetas deberemos aumentar el numero de ellas en inotify, de esta manear quedara aumentado a 100000:
1 |
$ echo fs.inotify.max_user_watches=100000 | sudo tee -a /etc/sysctl.conf; sudo sysctl -p |
Fuentes: El Baul del Programador , En mi maquina funciona
Deja un comentario