Create backup.sh
Browse files
backup.sh
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# 备份数据库到固定的文件名,覆盖上一次的备份
|
4 |
+
pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -F c -b -v -f "/app/backups/backup.dump"
|
5 |
+
|
6 |
+
# 检查备份是否成功
|
7 |
+
if [ $? -eq 0 ]; then
|
8 |
+
echo "数据库备份成功,正在上传到 WebDAV..."
|
9 |
+
|
10 |
+
# 使用 curl 将备份文件上传到 WebDAV,使用基本身份验证
|
11 |
+
curl -T "/app/backups/backup.dump" \
|
12 |
+
--user "${WEBDAV_USER}:${WEBDAV_PASSWORD}" \
|
13 |
+
"${WEBDAV_URL}/backup.dump"
|
14 |
+
|
15 |
+
if [ $? -eq 0 ]; then
|
16 |
+
echo "备份文件成功上传到 WebDAV"
|
17 |
+
else
|
18 |
+
echo "备份文件上传到 WebDAV 失败"
|
19 |
+
fi
|
20 |
+
else
|
21 |
+
echo "数据库备份失败"
|
22 |
+
fi
|