Skip to content

Instantly share code, notes, and snippets.

@libraplanet
Created February 27, 2017 11:32
Show Gist options
  • Save libraplanet/a5255a1c4d345ccc19f2075bddaa0f4e to your computer and use it in GitHub Desktop.
Save libraplanet/a5255a1c4d345ccc19f2075bddaa0f4e to your computer and use it in GitHub Desktop.
sync google drive using grive2 with white list.
[Unit]
Description=grive sync service
After=network.target
[Service]
User=grive
Group=grive
Type=simple
ExecStart=~/grive.sh "samle"
KillMode=control-group
[Install]
WantedBy=multi-user.target
#!/bin/bash
function loadConf() {
local base_dirpath=`dirname ${0}`
local conf_dirname=".conf"
local fname="${1}.conf"
echo "conf file=${conf_dirname}/${fname}"
. "${base_dirpath}/${conf_dirname}/${fname}"
}
function main() {
local sync_local_path=
local trash_path=
local sync_remote_path=
echo "process start."
echo "load conf."
loadConf "${1}"
echo "SYNC_LOCAL_PATH=${SYNC_LOCAL_PATH}"
echo "SYNC_REMOTE_PATH_LIST=${SYNC_REMOTE_PATH_LIST[@]}"
echo "SYNC_REMOTE_PATH_LIST.COUNT=${#SYNC_REMOTE_PATH_LIST[*]}"
if [ ! -d "${SYNC_LOCAL_PATH}" ] ;then
echo "sync local path is not found. (${SYNC_LOCAL_PATH})" 1>&2
exit 1
fi
if [ ${#SYNC_REMOTE_PATH_LIST[*]} -le 0 ] ;then
echo "sync remote path list is ${#SYNC_REMOTE_PATH_LIST[*]}." 1>&2
exit 1
fi
sync_local_path="${SYNC_LOCAL_PATH}"
sync_local_trash_path="${SYNC_LOCAL_PATH}/.trash"
echo "sync task start."
echo "sync_local_path=${sync_local_path}"
echo "sync_local_trash_path=${sync_local_trash_path}"
for sync_remote_path in "${SYNC_REMOTE_PATH_LIST[@]}"
do
echo "grive -p \"${sync_local_path}\" -s \"${sync_remote_path}\""
grive -p "${sync_local_path}" -s "${sync_remote_path}"
done
echo "sync end."
echo "cleanap start."
if [ -d "${sync_local_trash_path}" ] ;then
echo "delete old files."
find "${sync_local_trash_path}/" -type f -mtime +5 -delete -print
echo "delete empty directories"
find "${sync_local_trash_path}/" -type d -empty -delete -print
else
echo "no trash directory. ${sync_local_trash_path}"
fi
echo "cleanap end."
echo "process end."
}
main $@
[Unit]
Description=grive sync timer
[Timer]
OnBootSec=10min
OnCalendar=*-*-* *:0/10:00
[Install]
WantedBy=timers.target
#sync to local path
SYNC_LOCAL_PATH="/home/grive/sync"
#sync llist rom remote path's
SYNC_REMOTE_PATH_LIST+=()
SYNC_REMOTE_PATH_LIST+=("/dir_0")
SYNC_REMOTE_PATH_LIST+=("/dir_1")
SYNC_REMOTE_PATH_LIST+=("/dir_2")
◆grive2
https://github.com/vitalif/grive2
◆install
-> http://yourcmc.ru/wiki/Grive2#Installation
◆define
・sync user
user : grive
group : grive
・sync dir
local : /home/grive/sync
drive : /dir_0, /dir_1, /dir_2
・scropt
~/grive.sh
~/.conf/sample.conf
◆first run. (with -a option.)
$ grive -a -p /home/grive/sync -s /work/sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment