【网盘】davfs把Alist的网盘(天翼)通过Webdav挂载到vps或本地,并配置宝塔自动备份

安装davfs,fuse

#centos:
yum install davfs2
yum install fuse

#debian
apt install davfs2
apt-get update && apt-get install -y fuse

(有些时候还要安装fuse3)

新建挂载位置,给权限

mkdir -p /Backup/VPS自动备份
chmod +x /Backup/VPS自动备份

配置Alist的webdav的URL、账号密码(注意一定要有/dav/),路径是/etc/davfs2/secrets

echo "http://127.0.0.1:端口/dav/Tianyi/VPS自动备份 Alist管理账号 密码" > /etc/davfs2/secrets

配置自启动:

centos7系统:

(格式:前面是webdav的路径,空格后面是本地挂载到的路径),路径是/etc/rc.local

echo "mount -t davfs http://127.0.0.1:端口/dav/Tianyi/VPS自动备份 /Backup/VPS自动备份" >> /etc/rc.local

Debian10系统:

由于debian10弃用了rc.local文件,使用systemd服务管理自启动,因此需要如下操作:

  • 1.在/opt目录下新建名为mount.sh的脚本
#!/bin/bash
sleep 30
mount -t davfs http://127.0.0.1:端口/dav/Tianyi/VPS自动备份 /Backup/VPS自动备份
  • 2.为该脚本文件添加可执行权限:
chmod +x /opt/mount.sh
  • 3.在 /etc/systemd/system/ 目录下创建一个新的 systemd 服务文件,mount-startup.service,并在其中添加以下内容:
[Unit]
Description=Mount davfs at startup

[Service]
Type=simple
ExecStart=/bin/bash /opt/mount.sh

[Install]
WantedBy=multi-user.target
  • 4.重新加载 systemd 配置:
systemctl daemon-reload
  • 5.启用该服务以使其在开机时自动运行:
systemctl enable mount-startup.service

配置fastab:

(格式:前面是webdav的路径,空格后面是本地挂载到的路径),路径是/etc/fstab

echo "mount -t davfs http://127.0.0.1:端口/dav/Tianyi/VPS自动备份 /Backup/VPS自动备份  davfs defaults 0 0" >> /etc/fstab

挂载命令:

(格式:前面是webdav的路径,空格后面是本地挂载到的路径)

mount -t davfs http://127.0.0.1:端口/dav/Tianyi/VPS自动备份 /Backup/VPS自动备份

留下评论