문제

I am trying to create a cronjob with the following specifics; Export to run weekly and dump files older than 3 weeks to be deleted from path. Please can you help create a sample script.

도움이 되었습니까?

해결책

The script (untested)

#!/bin/bash

# Set path to backup directory
BK_PATH = /path/to/backups/

# If 3 is there remove it
if [ -f "${BK_PATH}3.tgz" ]
then
  rm -rf ${BK_PATH}3.tgz
fi

# If 2 is there, it becomes 3
if [ -f "${BK_PATH}2.tgz" ]
then
  mv ${BK_PATH}2.tgz ${BK_PATH}3.tgz
fi

# If 1 is there, it becomes 2
if [ -f "${BK_PATH}1.tgz ]
then
  mv ${BK_PATH}1.tgz ${BK_PATH}2.tgz
fi

# Create 1.
tar czvf ${BK_PATH}1.tgz $1

Then, in your crontab:

0 0 * * 6 /path/to/the/script /path/the/thing/you/want/backedup
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top