windows - Ubuntu 中的 Windows FTP 清理脚本
问题描述
我正在使用 Ubuntu 20.04.3 LTS,我正在使用 Graeme 的 Windows 操作系统的 FTP 清理脚本 - https://stackoverflow.com/a/12552795/17189713
几个月来,我面临着一个我不知道如何解决的问题。
问题是该脚本正在删除除所需日期之外的每月 01 至 09 生成的备份文件。
让我详细说明。
现在是11月1日。所以在 FTP 服务器中,我应该在 10 月 26 日至 31 日和 11 月 1 日有 7 个副本,但我现在只有 6 个副本,即 10 月 26 日至 31 日。
所以明天,11 月 2 日,我将在 FTP 服务器中改为 5 个副本(27 日到 31 日),因为脚本不断删除它生成的备份文件,因为我怀疑这是由于前面的数字“0”。
等等等等。
我正在使用它为我的网箱生成备份:
pg_dump -h localhost -U {removed} > /home/backup/backup_$(date +"%Y_%m_%d_%I_%M_%p").sql
备份文件名是哪个
备份_2021_11_01_12_00_AM.sql
以下是我正在使用的 FTP 清理代码:
#!/bin/bash
# get a list of files and dates from ftp and remove files older than ndays
ftpsite=""
ftpuser=""
ftppass=""
putdir="/"
ndays=7
# work out our cutoff date
MM=`date --date="$ndays days ago" +%b`
DD=`date --date="$ndays days ago" +%d`
echo removing files older than $DD $MM
# get directory listing from remote source
listing=`ftp -pin $ftpsite <<EOMYF
user $ftpuser $ftppass
binary
cd $putdir
dir
quit
EOMYF
`
lista=( $listing )
# loop over our files
for ((FNO=0; FNO<${#lista[@]}; FNO+=9));do
# month (element 5), day (element 6) and filename (element 8)
#echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]} File: ${lista[`expr $FNO+8`]}
# check the date stamp
if [ ${lista[`expr $FNO+5`]}=$MM ];
then
if [[ ${lista[`expr $FNO+6`]} -lt 10#$DD ]];
then
# Remove this file
echo "Removing ${lista[`expr $FNO+8`]}"
ftp -pin $ftpsite <<EOMYF2
user $ftpuser $ftppass
binary
cd $putdir
delete ${lista[`expr $FNO+8`]}
quit
EOMYF2
fi
fi
done
Window 服务器没有 SFTP 连接。
有谁知道如何解决这个问题或有任何替代脚本可以分享?
解决方案
推荐阅读
- php - 使用 PHP 的异步通知
- ios - 如何在 Swift 中创建一个使新对象成为前一个对象的按钮?
- oracle - Oracle SQL 自动更新来自不同数据库的表
- javascript - 重定向似乎不可靠
- python - 将 DataFrame 转换为数组后,使用的内存增加了 8 倍。为什么?
- html - 范围到 HTML 删除部分字符串
- reactjs - 如果在 console.log 中成功获取数据,如何显示成功消息?
- javascript - 通过 JavaScript matchMedia 切换 HTML 视频源
- mysql - 表中是否可以有一个切换唯一索引?
- python - 502错误的网关。在“digitalocean”上实施应用程序后