Skip to content

Instantly share code, notes, and snippets.

@psyao
Last active March 14, 2018 21:29
Show Gist options
  • Save psyao/2e00c7884e7e1ce0c182 to your computer and use it in GitHub Desktop.
Save psyao/2e00c7884e7e1ce0c182 to your computer and use it in GitHub Desktop.
Extra provisioning for Laravel Homestead
#!/bin/sh
if [ ! -f /usr/local/extra_homestead_software_installed ]; then
echo 'Installing some extra software'
# Set the timezone
sudo timedatectl set-timezone Europe/Zurich
# Install french language pack
sudo apt-get install language-pack-fr -y
# Set database backup cron
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 all databases into a single SQL file
echo "Backing up all databases..."
mysqldump -R -u \$user -p\$password --all-databases > "\${backup_path}/00_\${date}.sql"
gzip \${backup_path}/00_\${date}.sql
# 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"
gzip \${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
# Remember that the extra software is installed
sudo touch /usr/local/extra_homestead_software_installed
echo "Extra software installed."
else
echo "Extra software already installed... Moving on..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment