Post

[PostgreSQL] Delete BackUp File

[PostgreSQL] Delete BackUp File

BackUp File 삭제 Command

7일 기준

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
command:
- /bin/bash
- -c
- |
  delete_date=$(date -d "7 day ago" +"%Y-%m-%d_%H:%M:%S")
  files=$(find /backups -type f)
  for file in $files; do
    if [[ $file =~ day ]]; then
      created=$(stat -c %y $file)
      echo $created
      if [[ $created < $ delete_date ]]; then
        echo "삭제할 파일: $file"
        rm $file
      fi
    fi
  done

24시간 기준

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
command:
- /bin/bash
- -c
- |
  delete_date=$(date -d "24 hour ago" +"%Y-%m-%d_%H:%M:%S")
  files=$(find /backups -type f)
  for file in $files; do
    if [[ $file =~ min ]]; then
      created=$(stat -c %y $file)
      echo $created
      if [[ $created < $ delete_date ]]; then
        echo "삭제할 파일: $file"
        rm $file
      fi
    fi
  done
This post is licensed under CC BY 4.0 by the author.