WEBVTT Kind: captions Language: en 00:00:00.480 --> 00:00:06.960 Hello Space Cadets. In this video, I'd like to 00:00:06.960 --> 00:00:14.360 introduce you to the topic of data backup under Linux. But first, some good news. Many of you have requested 00:00:14.360 --> 00:00:20.560 that our Linux distribution TuxWiz be available in a so-called stable version 00:00:20.560 --> 00:00:28.160 . Until now, TuxWiz was only available as a so-called rolling version. This is based on 00:00:28.160 --> 00:00:35.880 the Debian branch sid, also known as unstable, and offers regular updates. It has 00:00:35.880 --> 00:00:41.000 the advantage that you don't have to reinstall your Linux system after each release 00:00:41.000 --> 00:00:48.160 . However, if you prefer stability or don't want new updates 00:00:48.160 --> 00:00:55.800 installed every day, I highly recommend our new TuxWiz Stable version. 00:00:55.800 --> 00:01:02.760 You can find it here on our website spacefun.ch in the Download section. There 00:01:02.760 --> 00:01:08.560 you'll find the TuxWiz button, and once you've entered your access ticket, you'll end up 00:01:08.560 --> 00:01:16.120 in the corresponding download folder. I've built TuxWiz Stable for Tuxwiz in both the mini version and 00:01:16.120 --> 00:01:22.320 the regular version, so you have the choice. I look forward to you 00:01:22.320 --> 00:01:29.000 trying out TuxWiz Stable and letting me know how it goes for you. But now back to the actual topic. This 00:01:29.000 --> 00:01:36.400 is about backup. First, we want to prepare a separate drive. We're making 00:01:36.400 --> 00:01:41.280 a lot of changes to our Linux system and want to make sure our data is backed up regularly 00:01:41.280 --> 00:01:46.880 . It doesn't make much sense 00:01:46.880 --> 00:01:52.920 to create the backup on the same drive I'm working on. That means I should use an external drive for the data backup 00:01:52.920 --> 00:01:59.440 . I have a relatively large external USB drive here. But there are also really 00:01:59.440 --> 00:02:04.560 large USB sticks you can use for this these days. And they're not that expensive. 00:02:04.560 --> 00:02:10.680 So now I have this drive and I want to mount it on my computer. To see how 00:02:10.680 --> 00:02:15.920 the drive is recognized under Linux, I can call up the following command. 00:02:15.920 --> 00:02:25.560 I enter the command 'sudo dmesg -w -T' in the terminal. We've already learned that. With 'dmesg' 00:02:25.560 --> 00:02:32.440 I can display the kernel ring buffer, and '-w' tracks the output, and '-T' 00:02:32.440 --> 00:02:38.040 displays the output in a human-readable time format. I'm now 00:02:38.040 --> 00:02:43.240 asked for a password again, and now my kernel ring buffer is displayed. There are some messages here 00:02:43.240 --> 00:02:48.080 that are from the 'ufw' firewall. If you haven't set up the firewall yet, 00:02:48.080 --> 00:02:54.080 be sure to watch my video on the subject. I'm now attaching this drive 00:02:54.080 --> 00:03:02.600 to this computer, and some messages are already appearing. I can 00:03:02.600 --> 00:03:08.680 cancel this with 'Ctrl' or 'Ctrl+C' because I already have the important information. I 00:03:08.680 --> 00:03:14.560 can see that a drive has been attached. It's from Western Digital and is called Elements 00:03:14.560 --> 00:03:20.880 1078. That's not relevant at the moment. What's important for us is 00:03:20.880 --> 00:03:27.880 this drive letter. It's displayed here. Under Linux, the device nodes are 00:03:27.880 --> 00:03:34.560 created here under '/dev'. 'ls /dev'. There are all the device nodes there, and now we have our 00:03:35.120 --> 00:03:41.880 '/dev/sdb'. That's new. First, we want to prepare this drive by 00:03:41.880 --> 00:03:47.800 partitioning and formatting it for Linux. I'm assuming you have a drive 00:03:47.800 --> 00:03:53.000 that you can use dedicated to Linux. It's important that this drive 00:03:53.000 --> 00:03:58.880 is formatted with a Linux-compatible file system, and we want 00:03:58.880 --> 00:04:05.320 to do that together here. First, I want to partition this drive. To do this, 00:04:05.320 --> 00:04:14.680 I'll use the 'cfdisk' command. I'll type 'sudo cfdisk /dev/sdb' in the terminal. We've noticed 00:04:14.680 --> 00:04:20.240 that my drive letter is 'sdb'. It could be something completely different for you. It's important 00:04:20.240 --> 00:04:25.920 that you find the right drive letter. You don't want to delete the wrong partition. So I 00:04:25.920 --> 00:04:30.080 'll go in here now. I see here, aha, 00:04:30.080 --> 00:04:36.160 this disk has about, I know, it has about a terabyte. So that's right, and this is my drive. There's already 00:04:36.160 --> 00:04:41.240 a partition there. I previously formatted it with the Windows-compatible file system. 00:04:41.240 --> 00:04:46.360 I want to delete it now. To do this, I'll click on 'Delete' here, and now it tells me 00:04:46.360 --> 00:04:51.520 above aha now I have 'free space' here. Nothing has happened yet. 00:04:51.520 --> 00:04:57.080 The setting is only actually written when I press 'Write'. I 00:04:57.080 --> 00:05:02.880 can select the individual commands in the program using the arrow keys. 00:05:02.880 --> 00:05:07.960 I can also select individual partitions using the up or down arrow. I'll say 'New' here to 00:05:07.960 --> 00:05:13.320 create a new partition. Now it asks me for the size. I'll enter the entire size here 00:05:13.320 --> 00:05:18.920 because I want to use my entire drive as a backup drive. I'll say it as the primary 00:05:18.920 --> 00:05:25.120 partition and now I can define a type here. It does that automatically now, 00:05:25.120 --> 00:05:29.840 so the standard type under Linux is also 'linux'. But I could look here again under 'Type' 00:05:29.840 --> 00:05:36.320 and see '83 Linux'. That's correct. I can confirm this with Enter. 00:05:36.320 --> 00:05:41.640 Now I can say 'Write' here, i.e. write. I now have to type 'yes' again to confirm, 00:05:41.640 --> 00:05:47.040 so that I can be sure that I 00:05:47.040 --> 00:05:53.520 have chosen the correct partition, the correct drive. Enter. And now I click on 'Quit'. I have now 00:05:53.520 --> 00:05:59.480 created a partition. I now have to format it, of course. For this there is the command 'mkfs' 00:06:00.280 --> 00:06:07.960 'sudo mkfs.ext4', that is the popular file system under Linux. 'mkfs' is available for various 00:06:07.960 --> 00:06:12.760 file systems. I can type tab tab here, and then I will see a few others. 00:06:12.760 --> 00:06:19.720 But we want to use 'ext4' for now. 'mkfs.ext4' Now I say the device node, i.e. the partition. I 00:06:19.720 --> 00:06:26.200 have now created a first partition on the 'sdb' drive. This means that this partition is 00:06:26.200 --> 00:06:36.240 now called '/dev/sdb1' '/dev/sdb1', this is my new partition. Now I can give the whole thing a 00:06:36.240 --> 00:06:42.160 label so that I can recognize it quickly later. So a label is simply like a 00:06:42.160 --> 00:06:48.320 little sticker that I stick on it, where I say, yes, this is now called a backup drive. Backup drive, 00:06:48.320 --> 00:06:51.920 you can call it whatever you want, of course. The important thing is that you can find it 00:06:51.920 --> 00:06:56.400 again. Maybe you even write it on the outside of the disk. I 00:06:56.400 --> 00:07:04.680 'm going to say Enter here. Yes, that means, it already has a file system and 00:07:04.680 --> 00:07:08.560 a label, I'm going to say 'proceed anyway'. You just have to be really sure that 00:07:08.560 --> 00:07:15.800 you get the right drive. Not much can really go wrong. 00:07:15.800 --> 00:07:22.320 If you have a classic IDE or SATA drive, for example, the 00:07:22.320 --> 00:07:29.160 drive letters usually start with /dev/sda, which is then your system drive. Nowadays, however, there are 00:07:29.160 --> 00:07:34.960 also these NVMe drives. They have slightly different names. Your external USB drive is 00:07:34.960 --> 00:07:42.040 probably still called 'sda' or 'sdb', though. You'll just have to check carefully with 'dmesg'. So, 00:07:42.040 --> 00:07:47.360 the journal is now being generated in the background and this drive 00:07:47.360 --> 00:07:53.360 is being formatted with the ext file system. We'll need this later because we want 00:07:53.360 --> 00:07:58.560 to be able to mount the drive. At the same time, let's take a look at whether I 00:07:58.560 --> 00:08:03.360 can access this drive with my user. I'm going to 00:08:03.360 --> 00:08:11.000 open a new terminal tab here with 'Ctrl' or 'Ctrl+Shift+T'. I now have a new terminal here. 00:08:11.000 --> 00:08:15.920 We can use a group. And we can give this group the right 00:08:15.920 --> 00:08:20.360 to write to this drive. Most Linux distributions already have a group 00:08:20.360 --> 00:08:27.960 called 'backup'. We can take a look at that: 'cat /etc/group'. This '/etc/group' file 00:08:27.960 --> 00:08:33.280 contains the group information for my Linux system. It 00:08:33.280 --> 00:08:38.600 lists all the groups that exist on my Linux system. I can also 00:08:38.600 --> 00:08:43.480 recommend my video 'Managing Users and Groups under Linux' if you're interested in learning more about it. I've now 00:08:43.480 --> 00:08:50.200 looked at this file. I could now type '|' grep backup' and now you see, 00:08:50.200 --> 00:08:54.560 there's this backup group. Now there's a little hint, because I've 00:08:54.560 --> 00:08:59.720 done a 'cat' here, so I'm displaying the file, and then I often do '| grep 00:08:59.720 --> 00:09:05.520 backup' myself. But that's actually useless, too. That's why it's called 'the useless use' 00:09:05.520 --> 00:09:12.160 of cat', i.e. the useless use of the cat command. Because I can 00:09:12.160 --> 00:09:19.160 use 'grep' to 'grep' the file directly. I could also do 'grep backup /etc/group', for example. It 00:09:19.160 --> 00:09:24.040 comes down to exactly the same thing. So you see, you can do it either way. You can 00:09:24.040 --> 00:09:29.320 find out for yourself however you want. It would be cleaner this way. But I'm 00:09:29.320 --> 00:09:33.400 actually sometimes lazy and have already typed 'cat', for example, and then 00:09:33.400 --> 00:09:38.640 I just add '| grep' and I'm done. You can try that out too. 00:09:38.640 --> 00:09:43.040 So, there's now a backup group and I'm already in it because I 00:09:43.040 --> 00:09:48.000 added myself to it beforehand. You don't have that yet. That's why you need to 00:09:48.000 --> 00:09:52.240 add your user account, in my case it's 'tux', to this group too. 00:09:52.240 --> 00:10:03.960 So 'sudo usermod -aG Backup' and then your user name. In my case, the user is called 00:10:03.960 --> 00:10:09.280 'tux'. Now, of course, I have to enter the password again. 00:10:09.280 --> 00:10:14.080 I'll put all these commands in a file for you, which I'll be happy to share 00:10:14.080 --> 00:10:20.040 with you in our Telegram community. Don't forget to join our Telegram community, because 00:10:20.040 --> 00:10:25.280 we regularly exchange information there about our videos here. So, I've now 00:10:25.280 --> 00:10:31.040 created a new user and added them to the group. You know, when you change group information, 00:10:31.040 --> 00:10:36.760 you actually have to log out and log back in for it to take effect, because 00:10:36.760 --> 00:10:41.800 only then does the user appear in this group. There's also this 'newgroup' command, 00:10:41.800 --> 00:10:47.680 which should be able to do that too, but for me it only works every other time. In the background, 00:10:47.680 --> 00:10:53.640 it has already formatted this new drive, my backup drive. So, I 00:10:53.640 --> 00:11:00.880 partitioned the drive and then formatted this partition with the ext4 file system. Now 00:11:00.880 --> 00:11:05.520 I'd like to see how we can integrate it. I've already prepared that here. 00:11:05.520 --> 00:11:12.120 So this is the file I'm sharing with you. You can use the 'lsblk' command 00:11:12.120 --> 00:11:19.320 to display the drive's UUID. Every drive has a unique designation, 00:11:19.320 --> 00:11:24.840 a unique identifier, the UUID. In this case, I'm finding it here 00:11:24.840 --> 00:11:30.880 because, as you can imagine, if I wanted to automatically mount this drive, for example, 00:11:30.880 --> 00:11:36.160 and address it with 'sdb1', but then accidentally have a second drive in there, 00:11:36.160 --> 00:11:40.160 your computer wouldn't know which one you wanted and might mount 00:11:40.160 --> 00:11:45.720 the wrong one. That's why you should mount it using this UUID. It 00:11:45.720 --> 00:11:52.480 's unique for this drive, or rather, for this partition. I'll make a note of it here and put 00:11:52.480 --> 00:11:58.320 it in my command that I've prepared here. It's not actually 00:11:58.320 --> 00:12:04.840 a command, but a configuration line for the '/etc/fstab' file. All the partitions to be mounted are listed there 00:12:04.840 --> 00:12:14.960 . Let's take a look at them now: 'sudo nano /etc/fstab'. Yes, 00:12:14.960 --> 00:12:21.400 for example, there's my root partition, my swap partition, they're all already in here. 00:12:21.400 --> 00:12:26.480 EFI is also in here, because I'm using an EFI system. And now 00:12:26.480 --> 00:12:31.240 I'd like to add this new line here. I'll explain it to you again. So, I've 00:12:31.240 --> 00:12:37.480 now found out the UUID with 'lsblk' and I want to 00:12:37.480 --> 00:12:44.080 mount the whole thing to '/media/Backup', let's make it small: '/media/backup'. This partition is of type 'ext4'. 00:12:44.080 --> 00:12:49.600 We formatted it with that, and here come the actual mount options. 00:12:49.600 --> 00:12:54.920 First, I'll tell it to use all standard mount options, which are 'defaults'. It shouldn't 00:12:54.920 --> 00:13:00.920 mount it automatically from the system, but rather with SystemD automount. SystemD is able 00:13:00.920 --> 00:13:08.840 to mount the drive automatically when accessed. That's called 'x-systemd.automount' and then there's 00:13:08.840 --> 00:13:16.920 'x-systemd.idle-timeout', which I set to 60 seconds. There I specify how long 00:13:16.920 --> 00:13:21.560 the drive should be unused before it's automatically unmounted. 00:13:21.560 --> 00:13:27.240 is a really great function. At the back is the order in which a file system check 00:13:27.240 --> 00:13:31.840 should be carried out during boot. With '2' I say that it should only happen at the very end, 00:13:31.840 --> 00:13:38.440 if the drive is mounted. Now I say 'Ctrl+O' 'Ctrl+X'. 00:13:38.440 --> 00:13:43.800 I've also included this information in this text file for you. You obviously have to adjust the UUID 00:13:43.800 --> 00:13:50.800 to your own UUID of your drive. So now I recommend that you 00:13:50.800 --> 00:13:57.400 really restart the computer , and we'll do this now , so that SystemD actually 00:13:57.400 --> 00:14:05.640 reads this information properly. We can do this here via the 'Logout / Restart' menu. Yes, the terminals are still open here 00:14:05.640 --> 00:14:10.840 , it can close them for now. So now you have already 00:14:10.840 --> 00:14:17.080 mounted a drive, i.e. an external USB drive, which could 00:14:17.080 --> 00:14:26.080 be an external hard drive or a USB stick, formatted it with a Linux-compatible file system and even 00:14:26.080 --> 00:14:33.720 assigned it a label. So now this drive is automatically 00:14:33.720 --> 00:14:45.440 mounted by default upon access. Let's take a look at that now. I have my backup drive here. It says 00:14:45.440 --> 00:14:49.800 '/media/backup' up here in the file system. But now I can see that I ca 00:14:49.800 --> 00:14:54.880 n't create any folders or files here. This is because we don't have any 00:14:54.880 --> 00:15:02.080 permissions to this drive yet. I'll go to 'media' 'cd /media' 'ls -al' and I can see here - 00:15:02.080 --> 00:15:07.120 if you've already watched my videos, you can 00:15:07.120 --> 00:15:10.960 watch the introduction to the command line again if you haven't seen it yet. There I explain exactly 00:15:10.960 --> 00:15:15.760 these file and folder permissions in Linux. You can definitely see here 00:15:15.760 --> 00:15:22.320 that only the user 'root' and the group 'root' are actually allowed to write to this directory 00:15:22.320 --> 00:15:28.320 . We'd like to change that now, of course. So to do that, I'll do 00:15:28.320 --> 00:15:35.200 'sudo chgrp backup', that's the name of the group, and this directory 00:15:35.200 --> 00:15:44.800 is now called 'backup' . 'ls- al' now I can see that the 'backup' group is now allowed in here, 00:15:44.800 --> 00:15:49.320 but they are not allowed to write anything there yet. They are only allowed to change to the directory. 00:15:49.320 --> 00:15:57.280 You can see this from the group permissions here. So now I'm going to do a 'chmod 775', so the owner 00:15:57.280 --> 00:16:02.600 and the group can read, write and execute. The rest of the users can only 00:16:02.600 --> 00:16:09.720 change to the 'backup' directory. I have to do this with 'sudo' of course. I don't have any permissions yet 00:16:09.720 --> 00:16:13.320 . So, now there's another great trick I want to show you. And it's really 00:16:13.320 --> 00:16:18.480 important because it allows you to master all the file system permissions in Linux 00:16:18.480 --> 00:16:24.120 . I'm showing you it exclusively in my video. There is the so-called 00:16:24.120 --> 00:16:36.720 sgid bit. You can set this with 'sudo chmod g+s backup'. You still have to write it correctly. So, 00:16:36.720 --> 00:16:40.040 now I've done it and something has changed here. You see, 00:16:40.040 --> 00:16:44.520 there's now a small 's' in here, and that means the following: 00:16:44.520 --> 00:16:49.360 if I now 00:16:49.360 --> 00:16:53.960 create a new file in this folder, I go into 'cd backup'. The folder is now empty; there's only 'Lost & Found' 00:16:53.960 --> 00:17:02.280 because it's a disk. I'm now creating a new file here. I'm going to say 'touch test'. 00:17:02.280 --> 00:17:07.360 Then, even if I created the file as the owner 'tux', it will 00:17:07.360 --> 00:17:13.360 automatically be assigned group permissions, i.e. the 'backup' group permission. This 00:17:13.360 --> 00:17:17.760 means that everyone in the 'backup' group can actually 00:17:17.760 --> 00:17:22.800 access this file. And so we can give everyone in the 'backup' group permissions to this 00:17:22.800 --> 00:17:27.840 backup drive. So you've now created the drive and 00:17:27.840 --> 00:17:31.760 mounted it. This is our test file. Now I can 00:17:31.760 --> 00:17:36.580 create a new folder here. This is my 'New Folder'. Now I can do 'ls -al' again in the terminal 00:17:36.580 --> 00:17:42.760 , and there you'll see 'tux' again, and the 'backup' group has full permissions and 00:17:42.760 --> 00:17:47.880 can access everything in this directory. So, we've now prepared the backup drive. 00:17:47.880 --> 00:17:53.320 and then you can look at the actual backup software in detail in the next video. I hope 00:17:53.320 --> 00:17:58.640 you enjoy it. It's not that easy, I know, but once you've done it once, you'll 00:17:58.640 --> 00:18:02.680 definitely be on the safe side. You only have to do it once; after that, we can 00:18:02.680 --> 00:18:08.800 use this backup drive again and again. Let me know in the comments. Don't forget 00:18:08.800 --> 00:18:13.800 to join our Telegram community. I can now repeat it again and again and try 00:18:13.800 --> 00:18:19.600 out our new TuxWiz stable version. I look forward to your feedback and see you soon. Bye, your Lioh.