skip to Main Content

I have a script that uploaded a compressed file to an ftp, it is the code that I show below.

This code works correctly, but I would like to adapt it so that once the file is uploaded, it deletes ftp files older than a week.

#!/bin/sh
HOST='xxx'
USER='xxx'
PASSWD='xxx'
DAY=`date +"%d%m%Y_%H%M"`

cd /temp
rm -fr backup
mkdir backup
cd backup

 
export GZIP=-9
tar -czvf $DAY-backup.tar.gz  --exclude="*/node_modules/*" /var/www/html/cars


FILE=$DAY-backup.tar.gz

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
binary
put $FILE
quit
END_SCRIPT
exit 0

2

Answers


  1. One option is to use a find command to catch file older than 7 days and delete it.
    So it give something like this :

    find . -type f -name ".*-backup.tar.gz" -mtime +7 -exec rm {} ;
    

    You can add this line in your script
    If you want to test first remove replace the exec part by print to display the files catched :

    find . -type f -name ".*-backup.tar.gz" -mtime +7 -print
    
    Login or Signup to reply.
  2. You can try this solution:

    # Purpose: This step is used to Purge 7 days old files
    export PROJECT_LOG="${PROJECT_HOME}/log";
    export APP_MAINT_LOG="APP.log"
    export LOG_RETAIN_DUR=7
    echo "Maintenance Job Started" > "${APP_MAINT_LOG}"
    echo "=========================================================================" >> "${APP_MAINT_LOG}"
    echo "${LOG_RETAIN_DUR} Day(s) Old Log Files..." >> "${APP_MAINT_LOG}"
    echo "=========================================================================" >> "${APP_MAINT_LOG}"
    find "${PROJECT_LOG}" -mtime +"${LOG_RETAIN_DUR}" -type f -exec ls -1 {} ; >> "${APP_MAINT_LOG}"
    #find "${PROJECT_LOG}" -mtime +"${LOG_RETAIN_DUR}" -type f -exec rm -rf {} ;
    echo "=========================================================================" >> "${APP_MAINT_LOG}"
    echo "Maintenance Job Completed" >> "${APP_MAINT_LOG}"
    cat "${APP_MAINT_LOG}"
    

    Note: I have commented the Remove file line, so that you can check and run !

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search