A collection of utility scripts for automating common Plesk server management tasks, including MySQL database backups and WordPress backup cleanup.
⭐ If you like this project, star it on GitHub — it helps a lot!
Overview • Scripts • Getting Started • Usage
This repository provides ready-to-use scripts for Plesk server administrators to automate routine maintenance tasks. Whether you're managing MySQL databases or WordPress installations, these scripts help streamline your server operations with minimal configuration.
Key Features:
- MySQL database backup automation for Windows and Linux
- Automated cleanup of old WordPress backup files
- Simple configuration with environment variables
- Compatible with Plesk's built-in tools
Automated MySQL database backup scripts for Plesk servers.
Available versions:
mysql-backup.bat- Windows batch scriptmysql-backup.sh- Linux shell script
Features:
- Backs up all MySQL databases
- Uses Plesk's MySQL credentials
- Creates individual SQL dump files per database
- Excludes system databases (information_schema, performance_schema, phpmyadmin)
- Automatically removes orphaned backup files for deleted databases
- Enhanced error handling and detailed logging
- Success/failure tracking with exit codes
- Self-update capability for automatic script updates
Automatically clean up old WordPress backup files to free up disk space.
Features:
- Scans all WordPress installations in Plesk vhosts
- Removes backups older than a specified number of days (default: 365 days)
- Dry-run mode to preview deletions without removing files
- Configurable retention period via environment variables
- Safe deletion with proper error handling
- Detailed logging with timestamps
- Exit codes for automation and monitoring
- Self-update capability for automatic script updates
For Linux scripts:
- Plesk server (Linux)
- Shell access with appropriate permissions
pleskCLI tool available
For Windows scripts:
- Plesk server (Windows)
- Administrator access
- MySQL admin password
-
Clone this repository or download the scripts you need:
git clone https://github.com/architecpoint/plesk-scripts.git cd plesk-scripts -
Make scripts executable (Linux only):
chmod +x mysql-backups/mysql-backup.sh chmod +x remove-old-wordpress-backups/remove-wordpress-backups.sh
-
Configure the scripts according to your environment (see individual script documentation).
All Linux scripts include built-in self-update capability to ensure you're always running the latest version from GitHub.
Manual update:
# Update the script to the latest version
./mysql-backups/mysql-backup.sh --update
./remove-old-wordpress-backups/remove-wordpress-backups.sh --updateAutomatic updates (recommended for cron):
# Enable auto-update with environment variable
AUTO_UPDATE=true ./mysql-backups/mysql-backup.sh
# Configure in cron for automatic updates
0 2 * * * AUTO_UPDATE=true /path/to/plesk-scripts/mysql-backups/mysql-backup.shConfiguration:
AUTO_UPDATE- Set totrueto enable automatic updates (default:false)UPDATE_CHECK_INTERVAL- Hours between update checks (default:24)GITHUB_BRANCH- GitHub branch to update from (default:main)
How it works:
- Each script contains embedded self-update functionality (no external dependencies)
- When enabled, scripts check for updates from the GitHub repository
- If a newer version is found, it's downloaded and validated
- The current version is backed up to
<script-name>.backup - The new version is installed atomically
- The script restarts automatically with the updated version
- Works silently in cron with no user interaction required
Linux:
# Run backup manually
./mysql-backups/mysql-backup.sh
# Run backup with auto-update enabled
AUTO_UPDATE=true ./mysql-backups/mysql-backup.sh
# Schedule with cron (daily at 2 AM with auto-update)
0 2 * * * AUTO_UPDATE=true /path/to/plesk-scripts/mysql-backups/mysql-backup.shWindows:
# Update the script with your MySQL admin password first
# Then run manually or schedule with Task Scheduler
mysql-backups\mysql-backup.batNote
For Windows, you must replace <password_for_mysql> in the batch file with your actual MySQL admin password before running.
# Preview what would be deleted without actually removing files (dry-run mode)
./remove-old-wordpress-backups/remove-wordpress-backups.sh --dry-run
# Run with default settings (removes backups older than 365 days)
./remove-old-wordpress-backups/remove-wordpress-backups.sh
# Run with custom retention period (e.g., 180 days)
DAYS=180 ./remove-old-wordpress-backups/remove-wordpress-backups.sh
# Preview custom retention period before deleting
DAYS=180 ./remove-old-wordpress-backups/remove-wordpress-backups.sh --dry-run
# Run with auto-update enabled
AUTO_UPDATE=true ./remove-old-wordpress-backups/remove-wordpress-backups.sh
# Schedule with cron (weekly on Sundays at 3 AM with auto-update)
0 3 * * 0 AUTO_UPDATE=true /path/to/plesk-scripts/remove-old-wordpress-backups/remove-wordpress-backups.shLinux (mysql-backup.sh):
- Backup location:
/backup/mysql/data/ - Automatically uses Plesk database credentials
Windows (mysql-backup.bat):
- Backup location:
%plesk_dir%\Databases\MySQL\backup\ - Requires manual MySQL password configuration
Environment Variables:
DAYS- Number of days to keep backups (default:365)- Example:
DAYS=180keeps backups for 6 months
- Example:
DRY_RUN- Set totrueto enable dry-run mode (default:false)- Example:
DRY_RUN=truepreviews deletions without removing files
- Example:
Command-line Options:
--dry-runor-n- Preview deletions without removing files--updateor--self-update- Update script to latest version from GitHub
- Test scripts first - Always test scripts in a non-production environment before deploying
- Use dry-run mode - Preview deletions with
--dry-runflag before running cleanup scripts - Monitor disk space - Ensure adequate storage for database backups
- Verify backups - Regularly test backup restoration procedures
- Schedule wisely - Run backups during off-peak hours to minimize server load
- Review logs - Check cron logs or Task Scheduler history for script execution status
- Enable auto-update - Set
AUTO_UPDATE=truein cron jobs to keep scripts up-to-date automatically - Check update logs - Review
[UPDATE]log entries to confirm successful updates
Problem: Script cannot download updates
# Verify curl or wget is installed
which curl wget
# Test GitHub connectivity
curl -I https://raw.githubusercontent.com/architecpoint/plesk-scripts/main/README.mdProblem: Update check happens too frequently
# Increase check interval to 7 days (168 hours)
UPDATE_CHECK_INTERVAL=168 AUTO_UPDATE=true ./mysql-backups/mysql-backup.sh
# Or disable auto-update and use manual updates
./mysql-backups/mysql-backup.sh --updateProblem: Script updated but using wrong branch
# Specify branch explicitly (e.g., develop, main)
GITHUB_BRANCH=develop AUTO_UPDATE=true ./mysql-backups/mysql-backup.shProblem: Script cannot connect to MySQL
# Verify Plesk database access
plesk db -e "show databases"Problem: Permission denied
# Ensure script has execute permissions
chmod +x mysql-backup.shProblem: Want to verify what will be deleted before running
# Use dry-run mode to preview deletions
./remove-old-wordpress-backups/remove-wordpress-backups.sh --dry-run
# Or with environment variable
DRY_RUN=true ./remove-old-wordpress-backups/remove-wordpress-backups.shProblem: Files not being deleted
- Check the backup path exists:
/var/www/vhosts/*/wordpress-backups - Verify file permissions for the script user
- Ensure correct
DAYSvalue is set - Run with
--dry-runflag to see what would be deleted
Warning
These scripts access sensitive server resources. Follow these security best practices:
- Store MySQL passwords securely (use environment variables or secure configuration files)
- Restrict script permissions to authorized users only
- Regularly review and audit script execution logs
- Ensure backup directories have appropriate access controls
Contributions are welcome! If you have improvements or additional scripts for Plesk management:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is provided as-is for use with Plesk servers. Please review individual scripts for specific usage terms.