Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # If you would like to do some extra provisioning you may
  4. # add any commands you wish to this file and they will
  5. # be run after the Homestead machine is provisioned.
  6.  
  7. if [ ! -f /etc/cron.daily/database-backup ]; then
  8. sudo bash -c "cat > /etc/cron.daily/database-backup" <<EOL
  9. #!/bin/bash
  10.  
  11. # Database credentials
  12. user="homestead"
  13. password="secret"
  14.  
  15. # Other options
  16. backup_path="/home/vagrant/backup"
  17. date=\`date +%Y-%m-%d\`
  18.  
  19. # Dump database into SQL file
  20. databases=\`mysql -u \$user -p\$password -e "SHOW DATABASES;" | grep -Ev "(mysql|information_schema|performance_schema|Database|sys)"\`
  21. for db in \$databases; do
  22. echo "Backing up database \${db}..."
  23. mysqldump --force --opt -u \$user -p\$password --databases \$db > "\${backup_path}/\${db}_\${date}.sql"
  24. done
  25.  
  26. # Delete files older than 30 days
  27. find \$backup_path/* -mtime +30 -exec rm {} \;
  28. EOL
  29. sudo chmod +x /etc/cron.daily/database-backup
  30. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement