


How to write a script for Vps to automatically back up web and mysql databases under Linux
1. Back up the web folder
1. Back up the /home/users/public_html directory
2. Modify the crontab to run at 3:22 on the first day of every week
Copy code The code is as follows:
22 3 * * 0 root run-parts /etc/cron.weekly
3. Copy the script to the /etc/cron.weekly directory
4. Modify permissions
Copy the code. The code is as follows:
chmod 0755 /etc/cron.weekly/webbackup.sh
5. The script is as follows
Copy code The code is as follows:
#!/bin/sh
filename=`date %y%m%d`
backup_dir="/root/dropbox/backup /web"
#delete all files 10 days ago
find $backup_dir -mtime 30 -name "*" -exec rm -rf {} \;
#each user you want backup
users= "baidu sina"
for user in ${users}; do
tar zcvf $backup_dir/$user$filename.tar.gz /home/$user/public_html
done
6 , note that the filename sentence is not a single quote, it is above the tab key
7. For the public_html directory of the user to be backed up, fill in the user into users
2. Daily backup of mysql database
1. For security reasons, create a new user backup, use a strong password (it can be automatically generated), and the global permissions are select, lock tables
2. Start execution at 3:00 every day, modify crontab
3 , copy the script to /etc/cron.daily
4, modify permissions
5, script content
Copy code The code is as follows:
#!/bin/sh
dbuser="backup"
dbpassword="youpassword"
datas="db1 db2 db3"
filename=`date %y%m%d`
bin_dir="/usr/local /mysql/bin"
backup_dir="/root/dropbox/backup/mysql"
#delete all files 10 days ago
find $backup_dir -mtime 10 -name "*" -exec rm -rf { } \;
#do each database backup
for data in ${datas}; do
$bin_dir/mysqldump --opt -u$dbuser -p$dbpassword $data | gzip > $backup_dir/ $data$filename.sql.gz
done
6. Same as the previous item 6
7. Fill in datas
The above is the detailed content of How to write a script for Vps to automatically back up web and mysql databases under Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

VS Code The methods of multi-line commenting are: 1. Shortcut keys (Ctrl K C or Cmd K C); 2. Manually add comment symbols (/ /); 3. Select menu ("Comment Block"); 4. Use extensions; 5. Recursive comments (/* /) and block comments ({/ and /}). Multi-line comments help improve code readability and maintainability, but overuse should be avoided.
