day = 1
item = "backups_all_ 2021.01.08|15.25.30.tar.gz"
d="$(date +%Y-%m-%d -d "$day days ago")"
if [[ item =~ "backups_all_$d|*.tar.gz" ]]
then
echo "ok"
fi
#!/bin/bash
day=2
item="backups_all_2021-01-08|15.25.30.tar.gz"
d="$(date +%Y-%m-%d -d "$day days ago")"
if [[ $item =~ backups_all_$d|.*.tar.gz ]]; then
echo "ok"
fi
#!/bin/bash
HOST=""
USER=""
PASSWD=""
UFILE="/bk"
DAYS=3
MONTHS=3
LIST="$(curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -l)"
for li in $LIST
do
EXIST=0
if [ "$li" = "." ] || [ "$li" = ".." ]
then
continue
fi
for day in `seq 0 $DAYS`
do
d="$(date +%Y-%m-%d -d "$day days ago")"
if [[ $li =~ backups_all_$d|.*.tar.gz ]]; then
EXIST=1
continue
fi
done
for month in `seq 0 $MONTHS`
do
d="$(date +%Y-%m-01 -d "$month month ago")"
if [[ $li =~ backups_all_$d|.*.tar.gz ]]; then
EXIST=1
continue
fi
done
if [ $EXIST -eq 0 ]
then
curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -X "DELE $li"
fi
done
test_del.sh: 23: test_del.sh: [[: not found
test_del.sh: 23: test_del.sh: .*.tar.gz: not found
test_del.sh: 32: test_del.sh: [[: not found
test_del.sh: 32: test_del.sh: .*.tar.gz: not found
#!/bin/bash
HOST=""
USER=""
PASSWD=""
UFILE="/bk"
DAYS=2
MONTHS=3
LIST="$(curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -l)"
for li in $LIST
do
EXIST=0
if [ "$li" = "." ] || [ "$li" = ".." ]
then
continue
fi
for day in `seq 0 $DAYS`
do
d="$(date +%Y-%m-%d -d "$day days ago")"
if [[ $li =~ backups_all_$d|.*.tar.gz ]]; then
echo days, file name - $li
EXIST=1
continue
fi
done
for month in `seq 0 $MONTHS`
do
d="$(date +%Y-%m-01 -d "$month month ago")"
if [[ $li =~ backups_all_$d|.*.tar.gz ]]; then
echo days, file name - $li
EXIST=1
continue
fi
done
if [ $EXIST -eq 0 ]
then
echo Del, file name - $li, EXIST - $EXIST
# curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -X "DELE $li"
fi
done
bash script.sh
days, file name - backups_all_2021-01-10|11-29-47.tar.gz
days, file name - backups_all_2021-01-10|11-29-47.tar.gz
days, file name - backups_all_2021-01-10|11-29-47.tar.gz
monts, file name - backups_all_2021-01-10|11-29-47.tar.gz
monts, file name - backups_all_2021-01-10|11-29-47.tar.gz
monts, file name - backups_all_2021-01-10|11-29-47.tar.gz
monts, file name - backups_all_2021-01-10|11-29-47.tar.gz
days, file name - backups_all_2021-01-09|11-29-47.tar.gz
days, file name - backups_all_2021-01-09|11-29-47.tar.gz
days, file name - backups_all_2021-01-09|11-29-47.tar.gz
monts, file name - backups_all_2021-01-09|11-29-47.tar.gz
monts, file name - backups_all_2021-01-09|11-29-47.tar.gz
monts, file name - backups_all_2021-01-09|11-29-47.tar.gz
monts, file name - backups_all_2021-01-09|11-29-47.tar.gz
days, file name - backups_all_2021-01-08|11-29-47.tar.gz
days, file name - backups_all_2021-01-08|11-29-47.tar.gz
days, file name - backups_all_2021-01-08|11-29-47.tar.gz
monts, file name - backups_all_2021-01-08|11-29-47.tar.gz
monts, file name - backups_all_2021-01-08|11-29-47.tar.gz
monts, file name - backups_all_2021-01-08|11-29-47.tar.gz
monts, file name - backups_all_2021-01-08|11-29-47.tar.gz
days, file name - backups_all_2021-01-07|11-29-47.tar.gz
days, file name - backups_all_2021-01-07|11-29-47.tar.gz
days, file name - backups_all_2021-01-07|11-29-47.tar.gz
monts, file name - backups_all_2021-01-07|11-29-47.tar.gz
monts, file name - backups_all_2021-01-07|11-29-47.tar.gz
monts, file name - backups_all_2021-01-07|11-29-47.tar.gz
monts, file name - backups_all_2021-01-07|11-29-47.tar.gz
days, file name - backups_all_2021-01-06|11-29-47.tar.gz
days, file name - backups_all_2021-01-06|11-29-47.tar.gz
days, file name - backups_all_2021-01-06|11-29-47.tar.gz
monts, file name - backups_all_2021-01-06|11-29-47.tar.gz
monts, file name - backups_all_2021-01-06|11-29-47.tar.gz
monts, file name - backups_all_2021-01-06|11-29-47.tar.gz
monts, file name - backups_all_2021-01-06|11-29-47.tar.gz
days, file name - test.tar.gz
days, file name - test.tar.gz
days, file name - test.tar.gz
monts, file name - test.tar.gz
monts, file name - test.tar.gz
monts, file name - test.tar.gz
monts, file name - test.tar.gz
backups_all_2021-01-06|11-29-47.tar.gz
backups_all_2021-01-07|11-29-47.tar.gz
backups_all_2021-01-08|11-29-47.tar.gz
backups_all_2021-01-09|11-29-47.tar.gz
backups_all_2021-01-10|11-29-47.tar.gz
test.tar.gz
backups_all_2021-01-06|11-29-47.tar.gz
backups_all_2021-01-07|11-29-47.tar.gz
backups_all_2021-01-08|11-29-47.tar.gz
test.tar.gz
#!/bin/bash
HOST=""
USER=""
PASSWD=""
UFILE="/bk"
DAYS=1
MONTHS=3
#for FILE in $(curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -l)
for FILE in $(ls -1); do
EXIST=0
echo "Processing $FILE"
if [ "$FILE" = "." ] || [ "$FILE" = ".." ]
then
echo "Skipping as . or .."
continue
fi
for day in $(seq 0 $DAYS)
do
d="$(date +%Y-%m-%d -d "$day days ago")"
if [[ $FILE =~ backups_all_$d.*.tar.gz ]]; then
echo "Need to delete $FILE because d=$d"
# curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -X "DELE $FILE"
continue 2
fi
done
for month in `seq 0 $MONTHS`
do
d="$(date +%Y-%m-01 -d "$month month ago")"
if [[ $FILE =~ backups_all_$d.*.tar.gz ]]; then
echo "Need to delete $FILE"
# curl -u $USER:$PASSWD ftp://$HOST/$UFILE/ -s -X "DELE $FILE"
continue 2
fi
done
done