Created
September 14, 2018 02:21
-
-
Save composite/e5430509b35ddb1a0d7b019b910b21c4 to your computer and use it in GitHub Desktop.
Backup files that file is older than a month ago.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| SOURCE='/path/to/source' | |
| DEST='/path/to/backup' | |
| TARGET="$DEST/$(date +'%G%m')" | |
| mkdir -p "$TARGET" | |
| function copyext() { | |
| loval TABC=$'\t' | |
| local FILE='' | |
| local MODDATE='' | |
| local LTEDATE=$(date -d '-1 month') | |
| for FILE in `find "$SOURCE" -name "*.$1"` | |
| do | |
| MODDATE=$(date -r "$FILE") | |
| if [[ $MODDATE < $LTEDATE ]]; then | |
| mv $FILE $TARGET | |
| echo "$FILE$TABC > $TABC$TARGET" | |
| fi | |
| done | |
| } | |
| copyext 'txt' | |
| copyext 'log' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment