Linux Backup with TAR and Cron Jobs


Author: Eli the Computer Guy
134300 View
35m 33s Lenght
1101 Rating


Info Level: Intermediate Presenter: Eli the Computer Guy Date Created: September 21, 2010 Length of Class: 35 Minutes Tracks Linux Prerequisites Introduction to Linux Installing Linux Basic Linux Tasks VIM for File Editing Navigation in Linux Users, Groups and Permissions in Linux Purpose of Class This class teaches students how to backup directories using TAR, and demonstrates how to schedule tasks using Cron Jobs. Topics Covered Backing Up Directories with TAR Recovering Directories with TAR Setting Up Cron Jobs for Scheduled Tasks Class Notes Backup Using TAR Backup = sudo tar --cvpzf backup.taz.gz --exclude/=directory (recursive) PATH --c = create new file (overwrites old file) --v = verbose --p = preserve permissions --z = compress --f = filename (very important) --exclude=DIRCECTORY is Recursive Naming Files with time = filename-$(date +%F-%T) Recover Files from a TAR File Recover = sudo tar --xvpzf FILE --C /DIRECTORY Capital -C = change to directory -x = extract Cron Jobs To Edit the Crontab File = sudo cron --e (first time it will ask you your default editor) Format = minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command * Wildcard for Every Minute/Day/Hour/Month?Day of Week Example to Backup Entire Server for 1am Every Morning = 0 1 * * * sudo tar -cvpzf /backup.tar.gz --exclude=/mnt /


Comments

  1. Bob = bunch of backups or backup of backup... cause you should always have more... :)
  2. What happens if you are trying to extract from a tar as a tarball by using 'z' in the command?
  3. I want to use my backup to reinstall and ovewrite the original
  4. usefull...superb
  5. your tutorials are like an IT videopedia for me, Golden! ty sir!
  6. Hi Eli I have a question for you, is there a way to backup an entire ubuntu system and restore it with this command or any other terminal like command? I am playing with a vm that is in a hypervisor which I do not have access to and I would like to have that vm backed up to a local machine (through ssh) and how will I go about restoring it?

    To my understanding, since I do not have access to the hypervisor I cannot use clonezilla or any other tool like that, I do not have access to the boot menu and such. So I am guessing (from what I am encounter) it is impossible to backup the vm, it is recommended to backup only certain files for example just the www folder instead of the whole system.
  7. Eli thanks for the informational video. quick question, when you did the crontab -e and it opened up crontab and had
    the # m h dom mon dow cheat-sheet, had you already input that into crobtab file for the sake of the video or did the earlier versions of Linux distributions already have that? I am using centos 7 and it doesnt have that little cheat-sheet. I know that its just a comment because of the # sign but i was just wondering. Thank you :)
  8. 10 peoples tried to do this on windows :P
  9. Hi very nice tutorial..
    But i have a question
    sudo requires password so how cronjob will take password from user?
  10. You were still doing backups with tar in 2011? Srsly?

    Sheesh, I stopped using tar for backups around 2000. That's when I learned that rsync existed. To another disk on the same server there's no advantage with rsync (but no disadvantage either). Rsync over ssh to a disk on another server and you get what is effectively a full backup but with data transfer amounting to less than an incremental backup. Rsync is designed to work well even with high-latency connections, so with the reduced data transfer daily full backups to remote sites is feasible. No faffing about backing stuff up onto removeable media and remembering to take it offsite.

    Plus you can have rsync automatically populate a directory with the files that changed or were deleted. So in one operation you can have a full backup and a decremental backup (like incremental but going back in time) with data transferred less than for an incremental backup.

    Or if you want you can have it create the equivalent of Microsoft's shadow volumes giving what appear to be full daily backups but with actual storage only of the unique files (don't forget to allocate some extra inodes to that disk when you create the filesystem) and data transfer amounting to less than an incremental backup.

    Tar was obsolete 16 years ago. You really ought to consider removing this video because it's giving people a bad solution to making backups. The only time tar is sensible is for archiving to tape, and archiving to tape isn't sensible when you can rsync to disk. So unless you're the NSA and keeping vast amounts of data forever, rsync is a far better solution.
  11. My only complaint is that you avoided saying gnu-zip when referring to gz. It's just easier to remember when you say 'z' stands for zip, and gz stands for Gzip (gnu-zip). But eh, probably I shouldn't complain about a 6-7 year old video.
  12. So far this has been the most useful video I've seen on the subject. The only thing I wanted to see that was not in the video was the syntax for adding multiple directories and excludes to the command. I don't want to backup my entire system since I am changing distros. But I do have multiple directories in many locations that I want to migrate over and many directories I want to leave behind.

    Also, as I understand it, '-z' is not a generic 'compress' flag it is specifically a '.zip' flag. My prefered compression format, bzip2, calls for a '-j' flag and creates the ubiquitous '.bz2' extension. I don't know the other compression options offhand. I'm sure you left that out of the video to minimize confusion. But I think it's useful information to have.
  13. I think there is mis editing in the terminal execution of the recovery/backup commands i.e. content exploration comes before back-up and recover. Anyways, thanks for the the tutorials.
  14. For me it's sudo tar -cvzf filename tar.gz FOLDERNAME but in order create it I have to be outside the folder. I use Linux Mint!
  15. My headphones exploned at the 1st second with my hears xD

    anyway, thank You for the tutorial Eli!! ^^
  16. thank you..............
  17. But what about say for February 28th or 29th if applicable for a scehduled cronjob?
    If i want to run a backup on the 30th of every month would I be right in assuming that if the month does not have 30 days then it would revert to running the job on the closest day?

    How about bi-weekly backups?
    I assume that's also setting the day interval to 14 right?

    Awesome tutorial man, I love your videos.
  18. The way you presented Linux videos were really fantastic and it was very crystal clear.Can you share me the link if you have complete Linux Courses Videos....
  19. Your awesome ....
  20. I just went through your whole Linux course tonight, massively appreciated, very clearly presented.