• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > 编写shell脚本将VPS上的数据备份到Dropbox网盘的方法

编写shell脚本将VPS上的数据备份到Dropbox网盘的方法

作者:goldensun 字体:[增加 减小] 来源:互联网

goldensun 通过本文主要向大家介绍了shell脚本编程大全,shell脚本视频教程,shell脚本编程入门,shell脚本编程,linux shell脚本等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

看到有人用dropbox备份网站数据,所以今天也试了一下,记得以前是一个python脚本,这是用的是bash 脚本,利用dropbox的api来上传下载的,很方便,脚本的地址是Dropbox-Uploader/dropbox_uploader.sh at master · andreafabrizi/Dropbox-Uploader · GitHub ,感谢作者分享这个脚本。

可以到git下载dropbox_uploader.sh,地址为:https://github.com/andreafabrizi/Dropbox-Uploader
或者也可以直接拷贝代码,保存为dropbox_uploader.sh,注意拷贝的时候最好是复制到文本编辑器里面,如notepad++之类的

#!/usr/bin/env bash
#
# Dropbox Uploader
#
# Copyright (C) 2010-2014 Andrea Fabrizi <andrea.fabrizi@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

#Default configuration file
CONFIG_FILE=~/.dropbox_uploader

#Default chunk size in Mb for the upload process
#It is recommended to increase this value only if you have enough free space on your /tmp partition
#Lower values may increase the number of http requests
CHUNK_SIZE=4

#Curl location
#If not set, curl will be searched into the $PATH
#CURL_BIN="/usr/bin/curl"

#Default values
TMP_DIR="/tmp"
DEBUG=0
QUIET=0
SHOW_PROGRESSBAR=0
SKIP_EXISTING_FILES=0
ERROR_STATUS=0

#Don't edit these...
API_REQUEST_TOKEN_URL="https://api.dropbox.com/1/oauth/request_token"
API_USER_AUTH_URL="https://www2.dropbox.com/1/oauth/authorize"
API_ACCESS_TOKEN_URL="https://api.dropbox.com/1/oauth/access_token"
API_CHUNKED_UPLOAD_URL="https://api-content.dropbox.com/1/chunked_upload"
API_CHUNKED_UPLOAD_COMMIT_URL="https://api-content.dropbox.com/1/commit_chunked_upload"
API_UPLOAD_URL="https://api-content.dropbox.com/1/files_put"
API_DOWNLOAD_URL="https://api-content.dropbox.com/1/files"
API_DELETE_URL="https://api.dropbox.com/1/fileops/delete"
API_MOVE_URL="https://api.dropbox.com/1/fileops/move"
API_COPY_URL="https://api.dropbox.com/1/fileops/copy"
API_METADATA_URL="https://api.dropbox.com/1/metadata"
API_INFO_URL="https://api.dropbox.com/1/account/info"
API_MKDIR_URL="https://api.dropbox.com/1/fileops/create_folder"
API_SHARES_URL="https://api.dropbox.com/1/shares"
APP_CREATE_URL="https://www2.dropbox.com/developers/apps"
RESPONSE_FILE="$TMP_DIR/du_resp_$RANDOM"
CHUNK_FILE="$TMP_DIR/du_chunk_$RANDOM"
TEMP_FILE="$TMP_DIR/du_tmp_$RANDOM"
BIN_DEPS="sed basename date grep stat dd mkdir"
VERSION="0.14"

umask 077

#Check the shell
if [ -z "$BASH_VERSION" ]; then
  echo -e "Error: this script requires the BASH shell!"
  exit 1
fi

shopt -s nullglob #Bash allows filename patterns which match no files to expand to a null string, rather than themselves
shopt -s dotglob #Bash includes filenames beginning with a "." in the results of filename expansion

#Look for optional config file parameter
while getopts ":qpskdf:" opt; do
  case $opt in

  f)
   CONFIG_FILE=$OPTARG
  ;;

  d)
   DEBUG=1
  ;;

  q)
   QUIET=1
  ;;

  p)
   SHOW_PROGRESSBAR=1
  ;;

  k)
   CURL_ACCEPT_CERTIFICATES="-k"
  ;;

  s)
   SKIP_EXISTING_FILES=1
  ;;

  \?)
   echo "Invalid option: -$OPTARG" >&2
   exit 1
  ;;

  :)
   echo "Option -$OPTARG requires an argument." >&2
   exit 1
  ;;

 esac
done

if [[ $DEBUG != 0 ]]; then
  echo $VERSION
  set -x
  RESPONSE_FILE="$TMP_DIR/du_resp_debug"
fi

if [[ $CURL_BIN == "" ]]; then
  BIN_DEPS="$BIN_DEPS curl"
  CURL_BIN="curl"
fi

#Dependencies check
which $BIN_DEPS > /dev/null
if [[ $? != 0 ]]; then
  for i in $BIN_DEPS; do
    which $i > /dev/null ||
      NOT_FOUND="$i $NOT_FOUND"
  done
  echo -e "Error: Required program could not be found: $NOT_FOUND"
  exit 1
fi

#Check if readlink is installed and supports the -m option
#It's not necessary, so no problem if it's not installed
which readlink > /dev/null
if [[ $? == 0 && $(readlink -m "//test" 2> /dev/null) == "/test" ]]; then
  HAVE_READLINK=1
else
  HAVE_READLINK=0
fi

#Forcing to use the builtin printf, if it's present, because it's better
#otherwise the external printf program will be used
#Note that the external printf command can cause character encoding issues!
builtin printf "" 2> /dev/null
if [[ $? == 0 ]]; then
  PRINTF="builtin printf"
  PRINTF_OPT="-v o"
else
  PRINTF=$(which printf)
  if [[ $? != 0 ]]; then
    echo -e "Error: Required program could not be found: printf"
  fi
  PRINTF_OPT=""
fi

#Print the message based on $QUIET variable
function print
{
  if [[ $QUIET == 0 ]]; then
	  echo -ne "$1";
  fi
}

#Returns unix timestamp
function utime
{
  echo $(date +%s)
}

#Remove temporary files
function remove_temp_files
{
  if [[ $DEBUG == 0 ]]; then
    rm -fr "$RESPONSE_FILE"
    rm -fr "$CHUNK_FILE"
    rm -fr "$TEMP_FILE"
  fi
}

#Returns the file size in bytes
# generic GNU Linux: linux-gnu
# windows cygwin:  cygwin
# raspberry pi:   linux-gnueabihf
# macosx:      darwin10.0
# freebsd:      FreeBSD
# qnap:       linux-gnueabi
# iOS:        darwin9
function file_size
{
  #Some embedded linux devices
  if [[ $OSTYPE == "linux-gnueabi" || $OSTYPE == "linux-gnu" ]]; then
    stat -c "%s" "$1"
    return

  #Generic Unix
  elif [[ ${OSTYPE:0:5} == "linux" || $OSTYPE == "cygwin" || ${OSTYPE:0:7} == "solaris" ]]; then
    stat --format="%s" "$1"
    return

  #BSD, OSX and other OSs
  else
    stat -f "%z" "$1"
    return
  fi
}

#Usage
function usage
{
  echo -e "Dropbox Uploader v$VERSION"
  echo -e "Andrea Fabrizi - andrea.fabrizi@gmail.com\n"
  echo -e "Usage: $0 COMMAND [PARAMETERS]..."
  echo -e "\nCommands:"

  echo -e "\t upload  <LOCAL_FILE/DIR ...> <REMOTE_FILE/DIR>"
  echo -e "\t download <REMOTE_FILE/DIR> [LOCAL_FILE/DIR]"
  echo -e "\t delete  <REMOTE_FILE/DIR>"
  echo -e "\t move   <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>"
  echo -e "\t copy   <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>"
  echo -e "\t mkdir  <REMOTE_DIR>"
  echo -e "\t list   [REMOTE_DIR]"
  echo -e "\t share  <REMOTE_FILE>"
  echo -e "\t info"
  echo -e "\t unlink"

  echo -e "\nOptional parameters:"
  echo -e "\t-f <FILENAME> Load the configuration file from a specific file"
  echo -e "\t-s      Skip already existing files when download/upload. Default: Overwrite"
  echo -e "\t-d      Enable DEBUG mode"
  echo -e "\t-q      Quiet mode. Don't show messages"
  echo -e "\t-p      Show cURL progress meter"
  echo -e "\t-k      Doesn't check for SSL certificates (insecure)"

  echo -en "\nFor more info and examples, please see the README file.\n\n"
  remove_temp_files
  exit 1
}

#Check the curl exit code
function check_http_response
{
  CODE=$?

  #Checking curl exit code
  case $CODE in

    #OK
    0)

    ;;

    #Proxy error
    5)
      print "\nError: Couldn't resolve proxy. The given proxy host could not be resolved.\n"

      remove_temp_files
      exit 1
    ;;

    #Missing CA certificates
    60|58)
      print "\nError: cURL is not able to performs peer SSL certificate verification.\n"
      print "Please, install the default ca-certificates bundle.\n"
      print "To do this in a Debian/Ubuntu based system, try:\n"
      print " sudo apt-get install ca-certificates\n\n"
      print "If the problem persists,
  


 

您可能想查找下面的文章:

  • 使用shell脚本实现ping对应IP所对应的人名(推荐)
  • 如何短时间内学好一门语言 shell脚本语言为例
  • 一个监控网卡流量的shell脚本
  • 101个shell脚本 猜数字游戏代码
  • shell脚本编程之数组
  • 编写shell脚本将VPS上的数据备份到Dropbox网盘的方法
  • 8个实用的Shell脚本分享
  • 8个实用的Shell脚本分享
  • shell脚本编程实现9*9乘法表
  • Shell实现的Oracle启动脚本分享

相关文章

  • Shell脚本中通过正则表达式匹配IP地址
  • mac 安装omyzsh后不执行~/.bash_profile、~/.bashrc的完美解决办法
  • Linux 编程之进程fork()详解及实例
  • LINUX下的流量监控shell脚本
  • linux下采用shell脚本实现批量为指定文件夹下图片添加水印的方法
  • linux shell 逻辑运算符、逻辑表达式详细介绍
  • awk中让人郁闷的system()函数
  • 每天一个linux命令 chgrp命令
  • real server 的一个启动脚本例子(推荐)
  • 深入理解Linux中的grep命令

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 一个简单的linux命令 cp
    • Shell脚本把文件从GBK转为UTF-8编码
    • Shell脚本判断Linux系统是32位还是64位的几种方法分享
    • Shell脚本字符串单引号和双引号的区别浅析
    • shell脚本nicenumber实现代码
    • Bash Shell中Shift用法分享
    • Linux Shell脚本系列教程(一):Shell入门
    • Shell脚本编程之判断语句
    • python实现Linux异步epoll代码
    • Shell脚本实现监控iptables规则是否被修改

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有