S
S
Sergey Goryachev2016-10-22 19:59:16
linux
Sergey Goryachev, 2016-10-22 19:59:16

How to set up cron for backups?

Actually, tell me where to dig.
It is necessary at a certain time (perhaps every few hours) to copy certain files and folders to the /mnt/yandexdisk/ folder.
All files at the destination must be replaced.
This begs two questions:
1. How to make a copy through a bash script?
2. How to run bash with cron?
Or is there another solution, more elegant or more interesting :)
Any help would be welcome.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DevMan, 2016-10-22
@webirus

1. no need to write any scripts, the copy command can be written directly in the cron.
2. crontab -eand insert the time and something like rsync -avzh /from /to. the time can be generated using crontab.guru
and the result should be something like:
0 0 * * * rsync -avzh /from /to- run backup every day at midnight.

C
CityCat4, 2016-10-22
@CityCat4

Well, a bicycle has been working for me for a long time, probably since 2000. It was written for FreeBSD, but after a little refinement it took off on linux. True, he solves a more complicated problem - to copy the entire specified directory (or database, though he understands only muscle) to point A, and at point A the previous information can either be overwritten or not overwritten.
Actually, it is pointless to run bash by cron - a simple command can be directly written to the crontab, a complex one - to the script file and the name of this file - to the crontab. Where is the crontab? /etc usually has a crontab file, but it's the "root" crontab that I usually avoid editing. In /etc/cron.d you can create files like

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
*/30 8-17 * * 1-5 root /usr/sbin/my.super.script

The example is a bit non-trivial and means that on weekdays (1-5) from 8 to 17 hours, my.super.script will run every half an hour (*/30)

L
lubezniy, 2016-10-22
@lubezniy

1. The cp command is our fso.
2. See if you have cron.* directories in /etc. If there is, then look at /etc/crontab - there you will understand how the cron launch is going. And you will surely find examples of scripts that work on cron in these directories.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question