Create a bash script to do the following on your CentOS6 VM.
Hint: Make sure you exclude the tar file itself from the backup.
1. How does tar work?
Tar is a program for archiving on Linux and related systems. Atypically for this kind of program, tar doesn’t offer compression by default. But the program is very popular because it offers the great advantage that entire directories can be merged into one file.
Install tar
With Ubuntu, tar should already be pre-installed. If you use another Linux or Unix distribution, install the helpful program with:
sudo apt-get install tar tar-doc
The tar-doc package is optional: It contains documentation of the archiving program.
When creating tar archives, you also have the option to create wildcards with an asterisk. If you create a new archive, always indicate the options first, then the file names of the archive that you want to create, and finally the files and folders that it should contain. In the following example, create an archive (-c) from two text files, compress it with gzip (-z), and write it to the file archive.tar.gz (-f):
tar -czf archive.tar.gz example_1.txt example_2.txt
If you want to combine all text files in a directory into an archive, use a corresponding wildcard:
tar -cf text_archiv.tar *.txt
You can also combine complete directories and their subdirectories into an archive. In the following example, /directory1 including all its subdirectories and the contained files is archived, excluding the subdirectory /directory1/subdirectory_x:
tar -cf archive.tar --exclude=”/directory1/subdirectory_x” /directory_1
In the following example, you extract (-x) the compressed (-z) archive that we created in the first example into another directory (-C):
tar -xzf archive.tar.gz -C /home/directory1/archive_directory
To add another file to an archive (which has to be uncompressed), enter the following command:
tar -rf archive.tar example_extra.txt
Create an incremental backup with tar
2. With tar, you can create regular incremental backups. You can also write your own backup script. For example, you can specify that a full backup is to be created once a month and then an incremental backup is performed daily. The following script also makes sure that old backups are regularly moved into folders sorted by date. In addition to tar, you also need cron. This daemon (a program that runs in the background) allows for time-based execution of other processes, and is always included with Ubuntu. First, open another text editor and create this script:
#!/bin/bash BACKUP_DIR=“/targetdirectory/backup” ROTATE_DIR=“/targetdirectory/backup/rotate” TIMESTAMP=“timestamp.dat” SOURCE=“$HOME/sourcedirectory ” DATE=$(date +%Y-%m-%d-%H%M%S) EXCLUDE=“--exclude=/mnt/*--exclude=/proc/*--exclude=/sys/*--exclude=/tmp/*” cd / mkdir -p ${BACKUP_DIR} set -- ${BACKUP_DIR}/backup-??.tar.gz lastname=${!#} backupnr=${lastname##*backup-} backupnr=${backupnr%%.*} backupnr=${backupnr//\?/0} backupnr=$[10#${backupnr}] if [ “$[backupnr++]” -ge 30 ]; then mkdir -p ${ROTATE_DIR}/${DATE} mv ${BACKUP_DIR}/b* ${ROTATE_DIR}/${DATE} mv ${BACKUP_DIR}/t* ${ROTATE_DIR}/${DATE} backupnr=1 fi backupnr=0${backupnr} backupnr=${backupnr: -2} filename=backup-${backupnr}.tar.gz tar -cpzf ${BACKUP_DIR}/${filename} -g ${BACKUP_DIR}/${TIMESTAMP} -X $EXCLUDE ${SOURCE}
The above steps are
3.This completes the script for the creation of an incremental backup with tar: Save the file as backup in the bin directory. You also need to export the path here and make the script executable:
PATH=$PATH:$HOME/bin chmod u+x $HOME/bin/backup
Theoretically, you can now start your backup script with sudo backup. But the idea behind the incremental backup is that the process is automatically run every day. For this, you access cron and change the so-called Crontab. This is the table that sets how cron tasks run. It has six sections:
Minutes (0-59) | Hours (0-23) | Days (1-31) | Months (1-12) | Days of the Week (0-7) | Task |
In these sections, you can either enter the corresponding number value (indicated in parentheses) or an asterisk (*). The latter basically for every possible value. One special feature is the days of the week section. Here you can set that a task is performed, for example, every Monday (1) or only on weekdays (1-5). Sunday can be given using two different values: Either 0 or 7 refers to Sunday, since for some people the week begins on this day and for others it ends.
In the command line, open the editor mode of cron with:
sudo crontab –e
5.Here, enter the following line:
6 00* * * /home/bin/backup
This means that the backup will be performed at 6:00 p.m. every day (and every month, regardless of the day of the week). Save your changes, and a daily incremental backup is ready to use.
7
Restore system from a backup
Nobody would ever wish it upon anyone, but sometimes the worst happens and your system needs to be completely restored. With tar, this is also relatively easily done and requires no additional script. A single command for a full backup isn’t possible though: It’s in the nature of incremental backups that multiple files must be unpacked. In the console, enter these command lines:
BACKUP_DIR=/targetdirectory/backup cd / for archive in ${BACKUP_DIR}/backup-*.tar.gz; do tar -xpzf $archive -C / done
Create a bash script to do the following on your CentOS6 VM. To back up your...
In Bash Write two scripts, 'backup.sh' and 'restore.sh' which do the following: backup.sh accepts a list of arguments which indicate the name o the output file and a list of files that should be backed up. Will take all of the files provided oher than the first and create a tar-ball(a tarred, gzipped file) with the name provided in the first argument. restore.sh Accepts a single filename of a tar-ball created by the script above and restores the files from...
Create a VBScript script (w3_firstname_lastname.vbs) that takes one parameter (folder name) to do the following 1) List all files names, size, date created in the given folder 2) Parameter = Root Folder name - The script should check and validate the folder name 3) Optionally, you can save the list into a file “Results.txt” using the redirection operator or by creating the file in the script. 4) Make sure to include comment block (flowerbox) in your code. 5) Sample run:-...
Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output: << CS Directory Analysis >> Date: ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files: 0 files Plain text files: 10 files File have read permissions: 3 files File have...
Code is in C#
Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...
Design an original, professional web site following the specifications listed below. This web site will be for a business you plan to set up for yourself or for someone else. The following is a detailed list of the requirements for your web site. READ them carefully. Instructions - Web Site Requirements for the web site: General: You will thoroughly test all your pages in more than one browser. All links MUST work. All graphics must show on the page. All...
TRUE/FALSE QUESTIONS: Foundations of Information Security and Assurance 1. There is a problem anticipating and testing for all potential types of non-standard inputs that might be exploited by an attacker to subvert a program. 2. Without suitable synchronization of accesses it is possible that values may be corrupted, or changes lost, due to over-lapping access, use, and replacement of shared values. 3. The biggest change of the nature in Windows XP SP2 was to change all anonymous remote procedure call (RPC)...
Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...
Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...