Debian x64
一 安装

按照官方安装教程。安装rclone.(官方安装教程。照搬了,按照官方操作即可,简单傻瓜试)
Linux安装步骤:
获取文件解压缩

curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64

复制二进制文件

cp rclone /usr/bin/
chown root:root /usr/bin/rclone
chmod 755 /usr/bin/rclone

安装 manpage

mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb 

其它安装方式,请参考官方安装。

二 使用。

使用命令:

 rclone config

屏幕将显示:

XXXXXXXX
e/n/d/q> n
输入n 新建一个
name> googledrive

googledrive可以根据自己需要自己命名,我这里使用的是googledrive,所以以gdrive命名。
输入8,选择googledrive。回车。

Google Application Client Id - leave blank normally.
client_id> 

提示以上文字。。这里留空即可,输入回车键

Google Application Client Secret - leave blank normally.
client_secret> 

提示以上文字,这里留空即可,输入回车键

Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> n

输入n,然后会出现一段文字,复制这个网址(https://**),在浏览器器中打开,允许权限,然后复制授权码。

然后在code后面粘贴。然后回车。。。。。。

[remote]
client_id = 
client_secret = 
token = {"AccessToken":"xxxx.x.xxxxx_xxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","RefreshToken":"1/xxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxx","Expiry":"2014-03-16T13:57:58.955387075Z","Extra":null}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

出现以上信息,输入y即可。
然后我们既可以使用以下命令:

rclone copy /home/source googledrive:backup         同步本地/home/source 到googledrive backup文件夹下。
rclone copy googledrive:backup /home/gdrive/backup  同步googledrive backup文件到本地/home/gdrive/backup下。
rclone sync /home/username/gdrive/   gdirve:sync    同步本地gdrive和googledrive sync文件夹。

 
列出启动器顶层的目录,实际意思就是显示googledrive中第一级文件夹。☺

rclone lsd googledrive:

查看googledrive中的所有文件列表

rclone ls  googledrive:

挂在googledrive的soft目录  到本地

rclone mount remote:path/to/files /path/to/local/mount &

例如:rclone mount googledrive:soft  /root/gdrive &

卸载挂载

fusermount -u /path/to/local/mount

例如:

fusermount -u /root/gdrive

更多命令,请查看 rclone config docs
三 备份自己的mysql数据库和网站文件:

cd ~
vim backup.sh

然后粘贴一下代码(请根据实际情况,修改参数)

#!/bin/bash
#Name:backup.sh
#backup sql and web files to googledrive.
#rclone关联账户名称记得加":"
rclonename=""
#备份数据库保存路径
backupdir=""
#数据库用户名
mysqluser=""
#数据库密码
mysqlpassword=""
#数据库名
mysqldb=""
#网站目录 譬如/var/www/html
webdata=""
#设置清空备份目录数据间隔天数
cd=""
if [ ! -d $backupdir ]; then
  mkdir $backupdir
fi
time=`date +%Y%m%d%H`
if [ $mysqldb ] && [ $mysqluser ] && [ $mysqlpassword ]; then
mysqldump -u $mysqluser -p$mysqlpassword $mysqldb | gzip > $backupdir/$mysqldb.$time.sql.gz
else
    echo "请设置数据库信息!不然无法备份!"
    exit 0
fi
if [ $webdata ]; then
    tar cvf $backupdir/webdata$time.tar.gz $webdata > /dev/null 2>&1
else
    echo "请设置网站目录!如果不设置将只备份数据库。"
fi
if [ $rclonename ]; then
    /usr/bin/rclone copy $backupdir $rclonename/$mysqldb && echo "$time备份成功到$mysqldb"

else
    echo "请设置rclone账号信息!"
    exit 0
fi
if [ $backupdir ]; then
    find $backupdir -name "*.gz" -type f -mtime +$cd -exec rm {} \; > /dev/null 2>&1
fi

backupdir 此为mysql和网站文件压缩后文件存放目录,备份实际上就是备份此目录。如果没有此目录,请手动添加。或者选择自己习惯的目录
webdir 此为网站的目录。
time 日期(自然无重复增长方式命名文件夹,方便自动清理过期文件。)
user 为mysql管理用户名,passwd为管理密码
dbname 为数据库名
代码中加入删除线的为根据实际情况,需要替换的。
保存后。执行 chmod u+x backup.sh
然后 crontab -e 新增:(/home/huya/backup.sh 为刚刚创建的backup.sh的目录,根据实际修改即可。设置每周一 3:30自动备份。)

30 3 * * 1 /home/huya/backup.sh 

代码安装:(转自Vicer)
安装:

#!/bin/bash
 
apt-get install -y nload htop fuse p7zip-full
 
KernelBit="$(getconf LONG_BIT)"
[[ "$KernelBit" == '32' ]] && KernelBitVer='386'
[[ "$KernelBit" == '64' ]] && KernelBitVer='amd64'
[[ -z "$KernelBitVer" ]] && exit 1
cd /tmp
wget -O '/tmp/rclone.zip' "https://downloads.rclone.org/rclone-current-linux-$KernelBitVer.zip"
7z x /tmp/rclone.zip
cd rclone-*
cp -raf rclone /usr/bin/
chown root:root /usr/bin/rclone
chmod 755 /usr/bin/rclone
mkdir -p /usr/local/share/man/man1
cp -raf rclone.1 /usr/local/share/man/man1/
mandb

自启动
使用方法:
1.复制内容.
2.将重命名为rcloned(只要不是rclone就可以).
3.填好REMOTE和LOCAL,复制到/etc/init.d文件夹内.
4.运行初始化命令:bash /etc/init.d/recloned init

#!/bin/bash
### BEGIN INIT INFO
# Provides:          rclone
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start rclone at boot time
# Description:       Enable rclone by daemon.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
REMOTE=''
LOCAL=''
CONFIG='/root/.config/rclone/rclone.conf'
DEMO='rclone'
 
[ -n "$REMOTE" ] || exit 1;
[ -x "$(which fusermount)" ] || exit 1;
[ -x "$(which $DEMO)" ] || exit 1;
 
case "$1" in
start)
  ps -ef |grep -v grep |grep -q "$REMOTE"
  [ $? -eq '0' ] && {
    DEMOPID="$(ps -C $DEMO -o pid= |head -n1 |grep -o '[0-9]\{1,\}')"
    [ -n "$DEMOPID" ] && echo "$DEMO already in running.[$DEMOPID]";
    exit 1;
  }
  fusermount -zuq $LOCAL >/dev/null 2>&1
  mkdir -p $LOCAL
  $DEMO mount $REMOTE $LOCAL --config $CONFIG --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 &
  sleep 3;
  DEMOPID="$(ps -C $DEMO -o pid=|head -n1 |grep -o '[0-9]\{1,\}')"
  [ -n "$DEMOPID" ] && {
    echo -ne "$DEMO start running.[$DEMOPID]\n$REMOTE --> $LOCAL\n\n"
    echo 'ok' >/root/ok
    exit 0;
  } || {
    echo "$DEMO start fail! "
    exit 1;
  }
  ;;
stop)
  DEMOPID="$(ps -C $DEMO -o pid= |head -n1 |grep -o '[0-9]\{1,\}')"
  [ -z "$DEMOPID" ] && echo "$DEMO not running."
  [ -n "$DEMOPID" ] && kill -9 $DEMOPID >/dev/null 2>&1
  [ -n "$DEMOPID" ] && echo "$DEMO is stopped.[$DEMOPID]"
  fusermount -zuq $LOCAL >/dev/null 2>&1
  ;;
init)
  fusermount -zuq $LOCAL
  rm -rf $LOCAL;
  mkdir -p $LOCAL;
  chmod a+x $0;
  update-rc.d -f $(basename $0) remove;
  update-rc.d -f $(basename $0) defaults;
  $DEMO config;
  ;;
esac
 
exit 0

最后修改:2022 年 08 月 23 日
如果觉得我的文章对你有用,请随意赞赏