0

I'm new to crontab. Usually to make a backup, without crontab, I give this command:

cd /
sudo tar -cvpzf Ubuntu_17.04_ROOT_BackUp.tgz --exclude=/proc --exclude=/lost+found --exclude=/media --exclude=/Ubuntu_17.04_ROOT_BackUp.tgz --exclude=/mnt --exclude=/sys /

Now with crontab:

#Open and write to my_username's `crontab` file

$ sudo crontab -e -u my_username

# m h  dom mon dow   command
  25 13  * * * cd / && export DISPLAY=:0 && /usr/bin/tar -cvpzf Ubuntu_17.04_ROOT_BackUp.tgz --exclude=/proc --exclude=/lost+found --exclude=/media --exclude=/Ubuntu_17.04_ROOT_BackUp.tgz --exclude=/mnt --exclude=/sys /

Is this right? Would this schedule my backup?

Zanna
  • 69,223
  • 56
  • 216
  • 327
IDK
  • 583
  • 1
  • 9
  • 19
  • 1. Why do you change directory to the root? Why not to a partition on an external drive (and exit with a loud complaint, if the external drive is not there); 2. Why do you export the DISPLAY variable? -- You can simplify the `tar` command line to backup only a small directory, so that it will be fast (within a few seconds), and then test in `crontab` with modified timing, for example `* * * * *` every minute) -- And when the test example works, you can set the time again to once daily or nightly and return to the complete backup in your `tar`command line. – sudodus Sep 11 '17 at 13:04
  • The loud complaint (a sound or synthetic speech message) can be replaced by creating a file or appending a line to a log file, when there is an error and when the backup has started and when it has finished (let us hope without errors) . And then you can check that file from a terminal window, if you want to know the status of the backup. – sudodus Sep 11 '17 at 13:21
  • 1) What you suggest seems cool, I'd like to do that, thing is I don't know how. For me is easier to create a backup in the root directory and then move it to my external hd then partitioning my external hd so that then I can back it up directly there. 2) The export command I added because of this https://askubuntu.com/questions/954723/crontab-issue-with-gedit and you lost me at the "loud compliant", like theoretically I know what you mean but in practice I got no idea. – IDK Sep 11 '17 at 15:39
  • Also, I know that more directories and folders could be left out from the backup to make it faster but I' m not sure on which ones to left out, and is not so painful (takes about 15 minutes) . – IDK Sep 11 '17 at 15:54
  • 1. If you have a fixed mountpoint for the external drive, you can simply use that as the target directory instead of the root directory `/mountpoint-of-external-drive/backupfile.tgz`; 2. OK, you want to see `tar` running in terminal window, and you want to write it to your graphical desktop. (I think most people let crontab jobs work in the background (with no terminal input/output.) ; 3. I meant just for testing that the crontab way to run the tar command works, you can let it do a very quick job, but never mind, it is not important, if you can wait for 15 minutes during the debugging. – sudodus Sep 11 '17 at 16:42
  • More about item 2. To show the tar job in the desktop you might have to run it in a terminal window like so `/usr/bin/xterm -e /usr/bin/tar ...` – sudodus Sep 11 '17 at 16:47

1 Answers1

0

You can add this entry to root's crontab instead:

25 13  * * * /usr/bin/tar -cvpzf /Ubuntu_17.04_ROOT_BackUp.tgz --exclude=/proc --exclude=/lost+found --exclude=/media --exclude=/Ubuntu_17.04_ROOT_BackUp.tgz --exclude=/mnt --exclude=/sys /

Instead of /Ubuntu_17.04_ROOT_BackUp.tgz, you can specify the directory under which you want these backups created.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Sisir
  • 1
  • 2