Birmingham mumbai



Download 15,21 Mb.
Pdf ko'rish
bet211/482
Sana13.01.2022
Hajmi15,21 Mb.
#355107
1   ...   207   208   209   210   211   212   213   214   ...   482
Bog'liq
Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)

[
 157 
]
Putting it all together – Writing an rsync 
backup script
Let's close this chapter with a Bash script that will not only prove to be very useful, 
but will also help you enhance your skills. The 
rsync
 utility is one of my favorites; it's 
very useful for not only copying data from one place to another, but also helpful for 
setting up a backup job. Let's use the following example 
rsync
 command to practice 
automation:
rsync -avb --delete --backup-dir=/backup/incremental/08-17-2020 /src /
target
This example 
rsync
 command uses the 
-a
 (archive) option, which retains the 
metadata of the file(s) it copies to the target, such as the timestamp and owner. 
The 
-v
 option gives us verbose output, so we can see exactly what 
rsync
 is doing. 
The 
-b
 option enables backup mode, which means that if a file on the target will 
be overwritten by a file from the source, the previous version of that file will be 
renamed so it won't be overwritten. Combining these three options, we simplify it 
into 
-avb
 rather than typing 
-a -v -b
. The 
--delete
 option tells 
rsync
 to delete any 
files in the target that aren't present in the source (since we used 
-b
, any file that is 
deleted will be retained). The 
--backup-dir
 option tells 
rsync
 that any time a file 
would have been renamed in this way (or deleted), to instead just copy it to another 
directory. In this case, we send any files that would have been overwritten to the 
/
backup/incremental/08-16-2020
 directory.
Let's script this 
rsync
 job. One 
problem we can fix in our script right away is the 
date that is present inside the directory we're using for the 
--backup-dir
. The date 
changes every day, so we shouldn't be hardcoding this. Therefore, let's start our 
script by addressing this:
#/bin/bash
CURDATE=$(date +%m-%d-%Y) 
We're creating a variable called 
CURDATE
. We're setting it equal to the output of the 
$(date +%m-%d-%Y)
 command. You can execute 
date +%m-%d-%Y
 in your terminal 
window to see exactly what that does. In this case, putting a command (such as 
date
) in parentheses and a dollar symbol means that we're executing the command 
in a 
sub-shell
. The command will run, and we're going to capture the result of that 
command and store it in the 
CURDATE
 variable.


Boosting Your Command-line Efficiency

Download 15,21 Mb.

Do'stlaringiz bilan baham:
1   ...   207   208   209   210   211   212   213   214   ...   482




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish