Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # If you would like to do some extra provisioning you may
- # add any commands you wish to this file and they will
- # be run after the Homestead machine is provisioned.
- if [ ! -f /etc/cron.daily/database-backup ]; then
- sudo bash -c "cat > /etc/cron.daily/database-backup" <<EOL
- #!/bin/bash
- # Database credentials
- user="homestead"
- password="secret"
- # Other options
- backup_path="/home/vagrant/backup"
- date=\`date +%Y-%m-%d\`
- # Dump database into SQL file
- databases=\`mysql -u \$user -p\$password -e "SHOW DATABASES;" | grep -Ev "(mysql|information_schema|performance_schema|Database|sys)"\`
- for db in \$databases; do
- echo "Backing up database \${db}..."
- mysqldump --force --opt -u \$user -p\$password --databases \$db > "\${backup_path}/\${db}_\${date}.sql"
- done
- # Delete files older than 30 days
- find \$backup_path/* -mtime +30 -exec rm {} \;
- EOL
- sudo chmod +x /etc/cron.daily/database-backup
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement