Skip to content

Instantly share code, notes, and snippets.

@leowebguy
Last active November 24, 2015 02:23
Show Gist options
  • Save leowebguy/ba5a11d992942774fbf1 to your computer and use it in GitHub Desktop.
Save leowebguy/ba5a11d992942774fbf1 to your computer and use it in GitHub Desktop.
Simplified bash code to execute database and files backup using CPanel Cron Job
#!/bin/bash
PATH=/usr/sbin:/sbin:/bin:/usr/bin
now="$(date +"%Y-%m-%d-%H%M")"
# backup root_db1 mysql database
mysqldump -u root_usr1 -h localhost -p'your-password' root_db1 | gzip -f > ./public_html/_backups/db1-$now.sql.gz &&
# backup site1/wp-content (wordpress content folder) and exclude .sass-cache folder (Cannot open: Permission denied)
tar czf ./public_html/_backups/site1-$now.tgz ./public_html/site1/wp-content --exclude=./public_html/site1/wp-content/themes/theme-child/.sass-cache &&
# backup site2/wp-content (wordpress content folder) and exclude _assets and cache folders
tar czf ./public_html/_backups/site2-$now.tgz ./public_html/site2/wp-content --exclude=./public_html/site2/wp-content/_assets --exclude=./public_html/site2/wp-content/cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment