Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Script automation: back up a file every 2 minutes

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Requirements: back up the file directory / home/backups/balalala to the / home directory every 2 minutes

Prepare for

1. Create the source directory

# mkdir / home/backups/balalala

Create the original file

# touch / home/backups/balalala/first.sh

2. Create a backup directory

# mkdir / home

First, write scripts with backup function

Create script

# vi / home/backup.sh write command

#! / bin/sh

Cp-r / home/backups/balalala/* / home/beifen

# backup the files in the / home/backups/balalala directory to the / home/beifen directory to execute the script file

For example: sh / home/backup.sh

Second, set the timing to execute this script.

The setup script is executed every 2 minutes.

Install crond

If the crond service is not installed, install the service first.

Check service status: service crond status modifies crontab content

Enter the command: crontab-e

Enter and continue to enter the command:

/ 2 * / home/backup.sh

# set to execute the script file every 2 minutes

Then, save exit: wq

# the first five fields of the sh script represent minutes (0-59), hours (0-23), day (1-31), month (0-12), and day of the week (0-6). Restart the crond service for the directory where the script resides

Enter command: service crond restart

III. Verification

1. Switch to / home/beifen

# cd / home/beifen

2. List files

# ls

You can see that the file first.sh is currently available.

3. Add new files to the / home/backups/balalala/ directory

# touch / home/backups/balalala/second.sh

4. Check again after 2 minutes for second.sh in the / home/beifen directory

Second.sh verification is successful!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report