This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| backup_script [2025/06/20 19:04] – [Remarks] thilo | backup_script [2025/12/01 12:45] (current) – [Remarks] thilo | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| - You want to schedule a backup to be done via a cron job. | - You want to schedule a backup to be done via a cron job. | ||
| - | - You want the script initiated from, and stored in a safe location | + | - You want the script initiated from, and stored in a safe location |
| - You do not wish to install SFTP just for these backups. | - You do not wish to install SFTP just for these backups. | ||
| Line 41: | Line 41: | ||
| - The netcat command must be available on the backup server. | - The netcat command must be available on the backup server. | ||
| - | - The router' | + | - The user executing the script on backup server |
| \\ | \\ | ||
| Line 101: | Line 101: | ||
| | | ||
| - | # It may be, that Tomato router has no - or other, wrong - timeother or no timee | + | # It may happen, that Tomato router has no - or other, wrong - time |
| - | # take date from localhost (i.e. backupserver) into backup filename | + | # take date from localhost (i.e. backup server) into backup filename |
| | | ||
| + | |||
| pushd ${DIR2BACKUP} > /dev/null | pushd ${DIR2BACKUP} > /dev/null | ||
| rm -f ${TRANSFER_FILENAME} | rm -f ${TRANSFER_FILENAME} | ||
| # | # | ||
| - | # | + | # |
| # VAR=`nvram get os_version` | # VAR=`nvram get os_version` | ||
| - | # seem not to work in bash via here doc, so write results into script file and source it | + | # seem not to work in bash via here doc, so write results into script file and source it. |
| - | # Further the individual filename is general | + | # Further the individual filename is generally |
| # | # | ||
| # Kill netcat zombies | # Kill netcat zombies | ||
| kill -9 `ps -ef | grep -v grep | grep netcat | sed -e "s/ [ ]*/ /g" | cut -d " " -f 2` 2> /dev/null | kill -9 `ps -ef | grep -v grep | grep netcat | sed -e "s/ [ ]*/ /g" | cut -d " " -f 2` 2> /dev/null | ||
| | | ||
| + | # Create the backup file on the router by executing the following commands (indented lines) there | ||
| ssh ${USER}@${ROUTER} -i ${LOCAL_ID_FILE} << | ssh ${USER}@${ROUTER} -i ${LOCAL_ID_FILE} << | ||
| rm -f ${SCRIPT_FILE} ${TRANSFER_FILENAME} ${PREFIX}_*_${DATE_REGEX}_${TIME_REGEX}.${EXT} | rm -f ${SCRIPT_FILE} ${TRANSFER_FILENAME} ${PREFIX}_*_${DATE_REGEX}_${TIME_REGEX}.${EXT} | ||
| Line 129: | Line 130: | ||
| tar -cvf ${TRANSFER_FILENAME} ${PREFIX}_*_${DATE_REGEX}_${TIME_REGEX}.${EXT} > /dev/null | tar -cvf ${TRANSFER_FILENAME} ${PREFIX}_*_${DATE_REGEX}_${TIME_REGEX}.${EXT} > /dev/null | ||
| cat ${TRANSFER_FILENAME} | nc ${BACKUPHOST} ${PORT} | cat ${TRANSFER_FILENAME} | nc ${BACKUPHOST} ${PORT} | ||
| - | sleep 5 # just wait a little | + | sleep 5 # just wait a little |
| rm -f ${SCRIPT_FILE} ${TRANSFER_FILENAME} ${PREFIX}_*_${DATE_REGEX}_${TIME_REGEX}.${EXT} | rm -f ${SCRIPT_FILE} ${TRANSFER_FILENAME} ${PREFIX}_*_${DATE_REGEX}_${TIME_REGEX}.${EXT} | ||
| | | ||
| Line 148: | Line 149: | ||
| fi | fi | ||
| # In total, keep only ${NO_OF_DIFF_FILES_TO_BE_KEPT} files - delete older files (of any day) | # In total, keep only ${NO_OF_DIFF_FILES_TO_BE_KEPT} files - delete older files (of any day) | ||
| - | OLDER_FILES=`ls | + | OLDER_FILES=`ls ${ALL_BACKUP_FILES_PREFIX}_${DATE_REGEX}_${TIME_REGEX}.${EXT} |
| if [ " | if [ " | ||
| echo "keep only ${NO_OF_DIFF_FILES_TO_BE_KEPT} in total, delete:" | echo "keep only ${NO_OF_DIFF_FILES_TO_BE_KEPT} in total, delete:" | ||