This is a Python script that allows you to create backups of your MySQL/MariaDB databases and upload them to your Dropbox account.
- Python 3.x installed on your system.
sudo apt install python3-
A Dropbox account with an access token. To create an access token, follow the official Dropbox documentation.
This guide will show you how to create a Dropbox app and give it write permissions.
- A Dropbox account. If you don't have one, sign up at https://www.dropbox.com.
-
Visit the Dropbox App Console at https://www.dropbox.com/developers/apps/create.
-
Select the type of access your app will need:
- Scoped access: Choose this option for more granular control over app permissions.
- Full dropbox: Choose this option if your app needs access to all files and folders in your Dropbox.
-
Enter a unique name for your app in the "App name" field.
-
Click the "Create App" button.
-
Once your app is created, you'll be redirected to the app's settings page. Here, you can manage your app's settings and permissions.
-
In the "OAuth 2" section, click the "Generate" button to create an access token. This token will be used to authenticate your app with Dropbox. Make sure to keep this token secure, as it grants access to your Dropbox account.
-
To set write permissions, go to the "Permissions" tab on the app's settings page.
-
Scroll through the list of permissions and enable the ones your app requires for writing. For example, if your app needs to write files and folders, enable the
files.metadata.write,files.content.write, andfiles.metadata.readpermissions. -
Click the "Submit" button at the bottom of the page to save your changes.
Your Dropbox app is now set up with write permissions. Use the generated access token to authenticate with the Dropbox API in your application.
-
MySQL or MariaDB installed on your system.
-
Clone the repository or download the script:
git clone https://github.com/MrZaKaRiA/DropboxSQL.git
-
Install the
dropboxpackage using pip:pip install dropbox
-
Open the script and replace the following placeholders with your own credentials:
db_user = 'your_db_user' db_password = 'your_db_password' dropbox_access_token = 'your_dropbox_access_token'
-
(Optional) Adjust the
backup_dirvariable if you want to use a different directory for temporary backup files:backup_dir = '/tmp'
To make the script executable, you can run the following command in your terminal:
chmod +x mysql_backup_to_dropbox.pyAfter you've made the script executable, you can run it directly:
./mysql_backup_to_dropbox.pyPlease note that you need to be in the same directory as the script to run the commands above. If the script is in a different directory, provide the full path to the script:
chmod +x /path/to/mysql_backup_to_dropbox.pyThe script will create a backup of each database (excluding information_schema and performance_schema) and upload it to a folder in your Dropbox account. The folder structure in Dropbox will be /sql_backups/YYYY-MM-DD-HH:MM:SS/.
Each backup file will be named {database}.sql.
This guide will show you how to schedule a script to run at midnight using crontab on Linux.
- A Linux system with
crontabinstalled. - A script you want to run at midnight.
-
Type
crontab -eon terminal to open the cron table for editing. If this is the first time you're running this command, it may prompt you to choose an editor (e.g., nano, vim, etc.). Choose the one you're comfortable with. -
Add the following line at the end of the file:
0 0 * * * /path/to/your/scriptReplace
/path/to/your/scriptwith the full path to the script you want to execute.This line means that the script will run at
0minutes and0hours (midnight) every day of the month, every month, and every day of the week. -
Save the file and exit the editor. The cron job is now scheduled.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.