emby自动备份脚本
侧边栏壁纸
  • 累计撰写 17 篇文章
  • 累计收到 698 条评论

emby自动备份脚本

syqman
2022-06-06 / 33 评论 / 2,026 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年06月06日,已超过1067天没有更新,若内容或图片失效,请留言反馈。
脚本说明

仅支持docker版emby的数据备份,自动删除7天以前的备份文件。

使用说明

root 目录下新建 embybackup.sh ,填入内容:

#!/bin/bash

# Emby主程序相关目录
embyserver_dir="/home/emby"
# 备份文件存放目录
bak_dir="/mnt/syqman/公益服备份"
# 时间格式化,如 20220602
DATE=`date +%Y%m%d`
# 备份脚本保存的天数
DEL_DAY=7
targz(){
    if [[ `which pv` == "" ]]; then
        apt install pv -y || yum install pv -y
    elif [[ $1 = '' ]]; then
        exit 1
    fi
    tar -cf - $2 | pv -s $(du -sk $2 | awk '{print $1}') | gzip > $1
}
# 创建日期目录
mkdir -p $bak_dir/$DATE
# 停止Emby Server容器服务
docker stop emby
cd $embyserver_dir
targz $bak_dir/${DATE}/emby-server.tar.gz ./
echo "emby-server备份完成······"
# 启动Emby Server容器服务
docker start emby

# 遍历备份目录下的日期目录
LIST=$(ls $bak_dir)
# 获取7天前的时间,用于作比较,早于该时间的文件将删除
SECONDS=$(date -d  "$(date  +%F) -${DEL_DAY} days" +%s)
for index in ${LIST}
do
    # 对目录名进行格式化,取命名末尾的时间,格式如 20200902
    timeString=$(echo ${index} | egrep -o "?[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")
    if [ -n "$timeString" ]
    then
        indexDate=${timeString//./-}
        indexSecond=$( date -d ${indexDate} +%s )
        # 与当天的时间做对比,把早于7天的备份文件删除
        if [ $(( $SECONDS- $indexSecond )) -gt 0 ]
        then
            rm -rf $index
        fi
    fi
done

给与脚本权限:

chmod +x embybackup.sh

手动执行下看有无报错:

bash embybackup.sh

指定的备份目录下,如有以日期命名的文件夹,如 20220606 ,并且文件夹下包含 emby-server.tar.gz 的文件,视为备份成功。
备份目录可设置为网盘挂载目录,即可以实现备份到云端。
加入定时备份,比如我每周一、四备份一次:

crontab -e

填入以下内容:

0 5 * * 1,4 /root/embybackup.sh > /dev/null

ctrl +x 保存退出。

1

评论 (33)

取消
  1. 头像
    Bryan
    Windows 10 · Google Chrome

    好家伙,不错不错

    回复
  2. 头像
    huiiikl
    Windows 10 · FireFox

    ψ(`∇´)ψ

    回复
  3. 头像
    crwovltwgi
    Windows 10 · Google Chrome

    想想你的文章写的特别好

    回复
  4. 头像
    fckefedccu
    Windows 10 · Google Chrome

    怎么收藏这篇文章?

    回复
  5. 头像
    rzrqcybdpd
    Windows 10 · Google Chrome

    不错不错,我喜欢看 https://www.237fa.com/

    回复
  6. 头像
    rczlgdouop
    Windows 10 · Google Chrome

    不错不错,我喜欢看 https://www.237fa.com/

    回复
  7. 头像
    yzdmjzhcxz
    Windows 10 · Google Chrome

    想想你的文章写的特别好https://www.ea55.com/

    回复
  8. 头像
    hwnljupfba
    Windows 10 · Google Chrome

    想想你的文章写的特别好https://www.ea55.com/

    回复
  9. 头像
    rrkndpunht
    Windows 10 · Google Chrome

    想想你的文章写的特别好www.jiwenlaw.com

    回复
  10. 头像
    fowlszuhbh
    Windows 10 · Google Chrome

    哈哈哈,写的太好了https://www.lawjida.com/

    回复
  11. 头像
    qxikwrexkg
    Windows 10 · Google Chrome

    文笔细腻,描写生动,画面感跃然纸上。

    回复
  12. 头像
    ogygqngvyi
    Windows 10 · Google Chrome

    语言通俗易懂,适合目标读者群体。

    回复
  13. 头像
    fmcsoetymi
    Windows 10 · Google Chrome

    文章深入浅出,既有深度思考,又不乏广度覆盖,令人叹为观止。

    回复
  14. 头像
    uwtttofkum
    Windows 10 · Google Chrome

    文章的叙述风格独特,用词精准,让人回味无穷。

    回复
  15. 头像
    fpvjkuommc
    Windows 10 · Google Chrome

    这篇文章不错!

    回复
  16. 头像
    klhlzesseg
    Windows 10 · Google Chrome

    绣衣使西汉迷案

    回复
  17. 头像
    aijtvokgji
    Windows 10 · Google Chrome

    李碧华鬼魅系列奇幻夜粤配

    回复
  18. 头像
    izucixiauw
    Windows 10 · Google Chrome

    第一类型危险

    回复
  19. 头像
    vptdhlvjti
    Windows 10 · Google Chrome

    人蛇大战李劲峰

    回复
  20. 头像
    rddnbjjqkl
    Windows 10 · Google Chrome

    隐秘王国

    回复
  21. 头像
    fellhbqjhn
    Windows 10 · Google Chrome

    卧底费瑞崛起

    回复
  22. 头像
    vvmgtzodzm
    Windows 10 · Google Chrome

    1600谋杀案

    回复
  23. 头像
    nsstxlpwjy
    Windows 10 · Google Chrome

    恐惧有限公司

    回复
  24. 头像
    sqbkwjihwd
    Windows 10 · Google Chrome

    广东小老虎

    回复
  25. 头像
    fqjvflqpeo
    Windows 10 · Google Chrome

    餐桌上的心声詹娜的初恋

    回复
  26. 头像
    mdosguszxt
    Windows 10 · Google Chrome

    我的西门小故事

    回复
  27. 头像
    bqsgripqop
    Windows 10 · Google Chrome

    神秘教父

    回复
  28. 头像
    bfnriwqolm
    Windows 10 · Google Chrome

    琼森帮归来

    回复
  29. 头像
    rlwhcbzbci
    Windows 10 · Google Chrome

    巴黎属于我们

    回复
  30. 头像
    cojhywepxl
    Windows 10 · Google Chrome

    小教父

    回复
  31. 头像
    nuyguglgiu
    Windows 10 · Google Chrome

    女人街再见了

    回复
  32. 头像
    bzfhchiaus
    Windows 10 · Google Chrome

    欲血僵尸

    回复
  33. 头像
    rbwpsyxtyx
    Windows 10 · Google Chrome

    伊格尔和鹤的旅程

    回复