Skip to content

Instantly share code, notes, and snippets.

@composite
Created September 14, 2018 02:21
Show Gist options
  • Select an option

  • Save composite/e5430509b35ddb1a0d7b019b910b21c4 to your computer and use it in GitHub Desktop.

Select an option

Save composite/e5430509b35ddb1a0d7b019b910b21c4 to your computer and use it in GitHub Desktop.
Backup files that file is older than a month ago.
#!/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