sh 基于docker的duplicity和amazon s3上传的duplicity备份脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 基于docker的duplicity和amazon s3上传的duplicity备份脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
AWS_ACCESS_KEY_ID=xxxxxxxx
AWS_SECRET_ACCESS_KEY=xxxxxxxxxx
PASSPHRASE=xxxxxxxxxxx

# directories, space separated
SOURCE="/mnt/home/"
BUCKET=s3+http://xxxxxxxxxx
BUCKETS3=s3://xxxxxxxxxxx
LOGFILE=/mnt/var/log/duplicity.log
LOGFILEREAL=/var/log/duplicity.log
# set email to receive a backup report
TMPOUTPUT=/tmp/output.tmp

DUPLICITY_CMD="docker run --hostname xxxxxxxx --rm -i --name duplicity -v /root/.cache/duplicity/:/root/.cache/duplicity/ -v /:/mnt/ -e AWS_ACCESS_KEY_ID='$AWS_ACCESS_KEY_ID' -e AWS_SECRET_ACCESS_KEY='$AWS_SECRET_ACCESS_KEY' -e PASSPHRASE='$PASSPHRASE' chardek/duplicity"

#echo $DUPLICITY_CMD

backup() {  
  INCLUDE=""
  for CDIR in $SOURCE
  do
    TMP=" --include  ${CDIR}"
    INCLUDE=${INCLUDE}${TMP}
  done
  rm -f $LOGFILEREAL
  # perform an incremental backup to root, include directories, exclude everything else, / as reference.
  BACKUP_CMD="$DUPLICITY_CMD --log-file $LOGFILE --allow-source-mismatch --full-if-older-than 30D $INCLUDE --exclude '**' / $BUCKET > $LOGFILE"
  echo $BACKUP_CMD
  eval $BACKUP_CMD
  if [ -n "$LOGFILE" ]; then
    bytes=`s3cmd du $BUCKETS3|awk {'print $1'}`
    mb=`expr $bytes / 1024 / 1024`
    gb=`expr $bytes / 1024 / 1024 / 1024`
    echo "BUCKET SIZE " >> $LOGFILEREAL
    echo "MB: $mb" >> $LOGFILEREAL
    echo "GB: $gb" >> $LOGFILEREAL
    /root/slack_notify duplicity Backup $LOGFILEREAL
  fi
}

list() {
  eval $DUPLICITY_CMD list-current-files $BUCKET
}

restore() {
  if [ $# = 2 ]; then
    eval $DUPLICITY_CMD restore --file-to-restore $1 $BUCKET $2
  else
    eval $DUPLICITY_CMD restore --file-to-restore $1 --time $2 $BUCKET $3
  fi
}

status() {
  eval $DUPLICITY_CMD collection-status $BUCKET
}

removeold() {
  eval $DUPLICITY_CMD remove-older-than 1M --force $BUCKET
}

if [ "$1" = "backup" ]; then
  backup
elif [ "$1" = "list" ]; then
  list
elif [ "$1" = "removeold" ]; then
  removeold
elif [ "$1" = "restore" ]; then
  if [ $# = 3 ]; then
    restore $2 $3
  else
    restore $2 $3 $4
  fi
elif [ "$1" = "status" ]; then
  status
else
  echo "
  duptools - manage duplicity backup
  
  USAGE:
  
  ./duptools.sh backup 
  ./duptools.sh list  
  ./duptools.sh status
  ./duptools.sh removeold
  ./duptools.sh restore file [time] dest
  "
fi

以上是关于sh 基于docker的duplicity和amazon s3上传的duplicity备份脚本的主要内容,如果未能解决你的问题,请参考以下文章

Docker搭建MySQL主从集群,基于GTID

基于docker的sqli-labs搭建

Docker 镜像错误:“/bin/sh: 1: [python,: not found”

波卡大咖汇AMA预告Zenlink & Acala 专场

基于Docker Container运行Flink1.7.1 Local Cluster模式

关于TPU-AMA(Ask Me Anything)