This page looks best with JavaScript enabled

rclone – installation and configuration

 ·  β˜• 5 min read  ·  🐧 sysadmin

Hello,

I will use rclone from https://rclone to backup my backup.org In this specific case I will use https://mega.nz and the appropriate configuration to copy files from the server to mega.nz. If you don’t have an account there, you can create one. Good morning everyone gets 50 GB of space for free.

Please note that at the moment there is a problem with 2FA for mega. Trying to compile an application from the source code by following the instructions from this page https://github.com/meganz/MEGAsync ends in an error. This is due to a compiler error, which in this case has too little memory, 128 MB RAM, 170 MB swap and too little CPU resources to complete the compilation properly. Process cc1plus is killed (kill) and the compilation of Crypto++ fails.

We need curl

CentOS

1
sudo yum install curl

Debian/Ubuntu

1
sudo apt-get install curl

or

1
sudo apt install curl

Next, execute the following command:

1
curl https://rclone.org/install.sh | sudo bash

Log in with increased privileges as a sudoers user.

1
sudo -i

Run rclone configuration with a command:

1
rclone config
  • Create a configuration file with a connection to your mega.nz
  • Choose n as a new remote)
  • Create a friendly name, e.g. mega or remote.
  • Create an 18 item, i.e. type the digits 18.
  • Give your login and password to your account in mega.nz
  • Next, we select n, because we do not want an advanced configuration, which I will write about another time.
  • Confirm our configuration with the letter y.
  • A at the very end we select q to leave the configuration.

Check now that the configuration is working.

1
rclone lsd mega:

If everything went well, you will be logged in to our account. On mega you can manually create a folder called backup. Then you can manually copy files to this folder using the lower command:

1
rclone copy /home/user mega:backup

But why bother? You can write yourself a script.

1
2
cd /home/user
vi backup.sh

Press the insert on the keyboard (ins) and paste the following content:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
 TIME=date +%b-%d-%y
 FILENAME=backup-bin-$TIME.tar.gz
 SRCDIR=/bin
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-bin-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-bin-$TIME.tar.gz
 FILENAME=backup-boot-$TIME.tar.gz
 SRCDIR=/boot
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-boot-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-boot-$TIME.tar.gz
 FILENAME=backup-dev-$TIME.tar.gz
 SRCDIR=/dev
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-dev-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-dev-$TIME.tar.gz
 FILENAME=backup-etc-$TIME.tar.gz
 SRCDIR=/etc
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-etc-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-etc-$TIME.tar.gz
 FILENAME=backup-home-$TIME.tar.gz
 SRCDIR=/home
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-home-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-home-$TIME.tar.gz
 FILENAME=backup-lib-$TIME.tar.gz
 SRCDIR=/lib
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-lib-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-lib-$TIME.tar.gz
 FILENAME=backup-lib64-$TIME.tar.gz
 SRCDIR=/lib64
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-lib64-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-lib64-$TIME.tar.gz!/bin/bash
 FILENAME=backup-lost+found-$TIME.tar.gz
 SRCDIR=/lost+found
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-lost+found-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-lost+found-$TIME.tar.gz
 FILENAME=backup-media-$TIME.tar.gz
 SRCDIR=/media
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-media-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-media-$TIME.tar.gz
 FILENAME=backup-mnt-$TIME.tar.gz
 SRCDIR=/mnt
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-mnt-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-mnt-$TIME.tar.gz
 FILENAME=backup-opt-$TIME.tar.gz
 SRCDIR=/opt
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-opt-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-opt-$TIME.tar.gz
 FILENAME=backup-reboot-$TIME.tar.gz
 SRCDIR=/reboot
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-reboot-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-reboot-$TIME.tar.gz
 FILENAME=backup-root-$TIME.tar.gz
 SRCDIR=/root
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-root-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-root-$TIME.tar.gz
 FILENAME=backup-run-$TIME.tar.gz
 SRCDIR=/run
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-run-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-run-$TIME.tar.gz
 FILENAME=backup-sbin-$TIME.tar.gz
 SRCDIR=/sbin
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-sbin-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-sbin-$TIME.tar.gz
 FILENAME=backup-srv-$TIME.tar.gz
 SRCDIR=/srv
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-srv-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-srv-$TIME.tar.gz
 FILENAME=backup-tmp-$TIME.tar.gz
 SRCDIR=/tmp
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-tmp-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-tmp-$TIME.tar.gz
 FILENAME=backup-usr-$TIME.tar.gz
 SRCDIR=/usr
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-usr-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-usr-$TIME.tar.gz
 FILENAME=backup-var-$TIME.tar.gz
 SRCDIR=/var
 DESDIR=/home/user/backup
 tar -cvpzf $DESDIR/$FILENAME $SRCDIR
 rclone copy /home/user/backup/backup-var-$TIME.tar.gz mega:backup
 rm -Rf /home/user/backup/backup-var-$TIME.tar.gz</pre>

Press Esc, type in :x and press Enter.

In order for a script to be executable, it must be given appropriate permissions.

1
chmod +x backup.sh

Now you can execute the script manually:

1
./backup.sh

If you want to automate this fairly lengthy process, add a task to the cron that will execute this script for you.If you want to automate this fairly lengthy process, add a task to the cron that will execute this script for you.If you want to automate this fairly lengthy process, add a task to the cron that will execute this script for you.

1
crontab -e

Press the insert (ins) and paste it:

1
00 04 * * * /bin/bash /home/user/backup.sh

Press Esc, enter :x and press Enter.

The script will be executed at 4 a.m. every 24 hours.

Explanation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
# shebang, meaning that the script will be executed by a particular 
interpreter, here bash.

TIME=date +%b-%%d-%d-%y 
# A variable that adds the current date

FILENAME=backup-bin-$TIME.tar.gz 
# File name after packing

SRCDIR=/bin
# The directory you want to copy

DESDIR=/home/user/backup
# The target directory to which the data is copied

tar -cvpzf $DESDIR/$FILENAME $SRCDIR
# Compressing the catalog

rclone copy /home/user/backup/backup-bin-$TIME.tar.gz mega:backup 
# copying directory to mega.nz

rm -Rf /home/user/backup/backup-bin-$TIME.tar.gz
# Removing the compressed file from the server

Finally, I’d like to make a final comment. The proc and sys directories will not allow you to make a copy, because they have files that are in use by the server, and more specifically by its processes.

Support the author with

sysadmin
WRITTEN BY
sysadmin
QA & Linux Specialist