Skip to content

Instantly share code, notes, and snippets.

@katoozi
Last active August 21, 2020 15:21
Show Gist options
  • Save katoozi/80de7204c1e36024d70d8995f7472901 to your computer and use it in GitHub Desktop.
Save katoozi/80de7204c1e36024d70d8995f7472901 to your computer and use it in GitHub Desktop.
postgresql daily backup at 1:00 AM
0 1 * * * /backups/backup.sh >/dev/null 2>&1
#!/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