Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 3789  / 3 Years ago, sat, august 21, 2021, 4:03:44

I want to copy everything in root / to my external hard disk before I upgrade my OS so I'll have everything just in case something goes wrong. Is the following the most appropriate command for it?


username@machine:/$ sudo cp -r . /media/username/TOSHIBA EXT/root_copy/

More From » backup

 Answers
2

To add to what P.P has said, you don't really want to copy every directory. I use tar to backup everything that I need, and "exclude" the directories I don't need. The command basically goes tar (options) BACKUP-FILENAME TARGET. If you run the following command it should do the trick.


sudo tar -cvpzf /media/username/TOSHIBA EXT/root_copy/root-copy.tar.gz --exclude='/mnt' --exclude='/run' --exclude='/proc' --exclude='/sys' --exclude='/media' --exclude='/dev' --exclude='/lost+found' --exclude='/tmp' --exclude='/boot' --exclude=".*lost+found" / 2> /root/tar-errors.txt


I know it looks like a lot, but tar is going to create a backup at /media/username/TOSHIBA /EXT/root_copy/. The file name is root-copy.tar.gz. It will exclude each of the directories that I have mentioned with --exclude, and lastly it will dump any errors that occur in a file named /root/tar-errors.txt.


Another benefit to using tar this way, is that the backup file will be a "zipped tarball". It's essentially a compressed archive so you will save space on your external drive.


I am sure there are more simple ways of doing this but I have always used this method to backup my systems.


[#3044] Sunday, August 22, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mouedi

Total Points: 420
Total Questions: 109
Total Answers: 116

Location: Philippines
Member since Wed, Aug 19, 2020
4 Years ago
mouedi questions
Mon, Mar 28, 22, 20:06, 2 Years ago
Sat, Dec 3, 22, 15:04, 1 Year ago
Thu, Mar 10, 22, 05:12, 2 Years ago
Wed, Jul 20, 22, 15:05, 2 Years ago
Thu, Aug 5, 21, 19:28, 3 Years ago
;