Skip to content

Instantly share code, notes, and snippets.

@lol97
Created December 31, 2023 14:29
Show Gist options
  • Select an option

  • Save lol97/0f6e5c3c69e69a1c36f54ebc83fcec81 to your computer and use it in GitHub Desktop.

Select an option

Save lol97/0f6e5c3c69e69a1c36f54ebc83fcec81 to your computer and use it in GitHub Desktop.
#!/bin/bash
#filename backup
fileName= db_retail_bck_$(date +%Y%m%d).log
path='/home/user/backup'
fullPath=${path}/${fileName}
echo ${fileName}
echo ${path}
echo ${fullPath}
#dobackup
if ! test -f ${fullPath}; then
mysqldump --no-tablespaces -u retail2 -p'Retail@--20@' db_toko > ${fullPath}
fi
#if exist and backup success delete file older than 7 days
if test -f ${fullPath}; then
find ${path} ! -type d -mtime +7 -name 'db_retail_bck_*.sql' -delete
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment