Last active
August 21, 2020 15:21
-
-
Save katoozi/80de7204c1e36024d70d8995f7472901 to your computer and use it in GitHub Desktop.
postgresql daily backup at 1:00 AM
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
0 1 * * * /backups/backup.sh >/dev/null 2>&1 |
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/bash | |
ignore_images_number=10 | |
counter=1 | |
DATE_FORMAT='+%Y-%m-%d--%H-%M' | |
ls /backups | grep '.sql' | sort -hr | column -t | while read line; do | |
if [ $counter -gt $ignore_images_number ] | |
then | |
{ | |
rm -rf /backups/$line | |
} || { | |
echo -e "${RED}Error While Deleteing backup.${NC}" | |
} | |
fi | |
counter=$((counter+1)) | |
done | |
PGPASSWORD="test_password" pg_dump -h 127.0.0.1 -U test_user -d test_db -v > /backups/`date ${DATE_FORMAT}.sql` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment