📺 Develpreneur YouTube Episode

Video + transcript

Python Backup Application Wrap Up

2023-11-02 •Youtube

Detailed Notes

We wrap up the series of tutorials as we build out a backup system that drops archive files into Amazon's S3 and related storage. This is our final tutorial in the series as we work on deploying and scheduling our script.

You can learn more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list, and you will periodically receive coupons for courses and notifications of the latest releases.

Transcript Text
[Music]
well hello and welcome back we are
wrapping up essentially this time our
little backup script and we're going to
walk through a couple last minute
cleanup things and deploy and we're to
talk about deploying a python script and
a couple little things we can do to help
ourselves out in the future now one of
the things that has sort of come
together is that we have got
um all of our little functions we built
now one of the things that we pulled
over this time around is uh we're going
to call it backup database oops I don't
need
that and uh we saw this in the prior one
where it's just a uh we just didn't pull
it into our backup script I don't think
and so what we've also
done it's just because we've got a you
know a lot of useful little things we've
now tweaked our script a little bit so
that it will allow us to we can use a um
a bucket
parameter and if we do that by itself
it's going to list the buckets that we
have uh connected for our account if we
do files and give it a bucket name then
it's going to list the files for that
bucket and then we've got of course our
other pieces we've also added dump which
gives us our data we give it a database
name and an output file so it would be
you know my database and you my
database.sql
and that one the dump is just going to
dump the file we could like we did with
our ZIP and store we could actually
upload our
file so if we
wanted uh let's see backup data base
let's just do that we'll just uh oh and
we can clean that we bring that over
this way a little bit so what we could
do here is we could say hey I'm going to
back up the database and then I'm going
to take take the out
file whatever output file is and I'm
going to send it to my bucket name but
then that means I've got to give it a
another bucket name so let's
not uh we'll save that for another time
uh actually what we could do
is yeah we'll leave it for now but
basically we could add another bucket
name and then send that out
or uh there's a couple different ways we
could do that for our backup database if
we wanted to keep it simple as number of
parameters then what we could do is
generate based on the database name we
could send a database in a bucket and
just do database.sql for output so we
don't have to send that file name in
anymore and then we could send it out to
a bucket but that's you know neither
here nor there that's some of the stuff
that you can do now so for example if we
do Python 3 Let's just show one real
quick uh bucket project is what we call
this and we're going to just call it
buckets if we do that then it's going to
list hey here's all of the buckets that
we have available if I want to take one
of those I don't even know what this
thing is let's see what this is uh that
one is going to be uh
files and then it's got a couple
different files there so it's got some
text files setting out
there obviously it's been sitting around
for a while too so that is our backup
script now what we can do let's open
this up a little bit more so I'm going
to go and I'm going to copy this script
out uh this is called bucket project and
I'm going to copy it out
to I'm going to SCP it there's a couple
ways you can do it but I'm going to SCP
this script out
to My Demo server and I'm going to do
I'm going go log into
that and so now if you look I've got my
bucket project there now what I'm going
to do is I'm going to try to run
that and this has got a thing called
shorty so let's start
with um let's do this let's do make uh
do I have a let me see if I have a
backup folder I do not so let's do this
I'm just going to do yeah I might do
that so I'm going to make something I'm
going to make a backup folder out on the
opt
and do something out
there and so let's just go ahead and
chod 777
that and I'm going to own it I'm to
change
that oops I need to pseudo
that so now this user owns that backup
so if I look I can see that on backup
I'm owning it I've got all the rights I
need so
now I'm going to go to backup
oh and I'm actually going to go ahead
and copy my script out here just because
just to keep it sort of clean so I'm
going to take
the uh bucket
project to here and then I'm going to
move that
to uh backup.
py so now I've got that so now I can try
to do Python 3 back up if I don't give
it anything then it's going to say hey I
don't have boto 3 so I need to do pip 3
install boto 3 we're going to look at
this in just a
second it's going to take it and we're
going to go ahead and we're going to
install that and we're going to try to
run it let's see what it
does now this one is going to probably
does not have Okay so that's l list out
of range so I don't have it any further
able to do that so let's just do buckets
I need to give it
something and so now I don't have my um
I don't have my AWS
installed so I'm going to need to do
that so I had to go through and install
my client on this guy so now when we run
it we can see here's my list of buckets
as we've seen before now one of things
we can do is that we can do a pip three
freeze and we can actually see all of
now this one's got a whole bunch of crap
but we can see all of the packages that
we have set up and so we can see for
example
boto3 photo core all that kind of stuff
so what we can do is we can take
this and if we do that into
requirements.
text
then one of the things we can do for an
install is uh to help us out is we can
do a pip 3
install with a-r give it the
requirements file and it will try to
install all of that stuff and now here
it's already satisfied because I've
already done it uh even though it looks
like it's picking a couple interesting
little versions along the way not sure
why it's doing
that but that's okay uh the bottom line
is is that makes it easier so we don't
have to like we just did run through an
install or run through run the project
or the application and then find out
that oh I'm missing all these
requirements we can just run it once
it's going to pick up whatever we're
missing and then we're off and running
otherwise it can get a little bit
tedious particularly when we're doing
things like uh like a Jango application
or something we've got a lot of
different things thrown in there or
there's some other things if you're
doing flask and some other uh python
projects that can get a little bit
complicated so now what we want to do is
one we're going to wait for this
to be done installing dependencies so we
can get through this little thing
apologies if that took a second but
that's okay I'll be right back when this
is done okay that took a long time I
apologize for that um let me clean up a
couple
things and so now what we've got is
we've got our little backup script so
what we would want to do in this case is
let's take uh let's just back up the
database so if we wanted to
do something complex I guess we could
have it like schedule we can just do our
very basic uh backup dump I think it's
lower I think it's uppercase and we're
just going to call it shorty.
SQL oops uh so I don't have
my I don't have my do my
config
so
and I probably need to clean up that
call in
there
three
two one so let me let's make sure I
don't have my user do I have Rob here
somewhere I don't okay so now I should
be able to
dump uh let's
see let's make sure I've got
it oh I did
not try one more
time nope that's why I don't have that
user set so if I set up my user properly
let me make sure I've got
him okay I do one second I need to
change my my
conf
3 2 1 okay so now that I've got it now
it will run now one of the things we can
do is we can actually scoll ripped this
so let's go
to uh we're going to make
scripts and we're going to do a
backup.
shell
three 2 one and so we're going to come
in here and we're going to create a
little script that's just going to do
Python 3 our backup
and we're going to call
this uh
shorty and we're going to give it this
it's going to give us our name so now
right it's going to give us a date so
what we can do here is if we chod plus X
the backup
script and then we do
um SLB
backup then if we go to our opt backup
what we see now is we've got our name
with us with the date in that and we
could also do it with time and such like
so that we can actually now we could
create a Cron job that runs us for
example every night at midnight and now
we've backed up our database now the
other thing we can do is if we want to
back up folders we could do the same
thing so I could do uh let me go back to
my home and let me go to my scripts and
what I can also do
well where did I put
that oops put that in the wrong place so
I'm going to put that to
scripts and so now if I go to scripts I
could also say I'm going to back up
my when I do this I also
want let me do this there we we go so
the same thing I can go back and I can
do opt
backup backup.
py and I can do uh what did I call that
I call
that uh where is where is the
see OH ZIP and store so
archive I called that
archive and so then I can take switch uh
let's see so I'm going to take my home
folder and I'm just going to call it uh
home let's do this demo 3 home.
zip and I think I also
need does that give me the bucket let's
see if I do
arive oh because it gives me a hardcoded
bucket name right now so I'm going to
change it well I'll leave that for now
so what I want to do is give it an extra
um give it something extra so I can give
it the right bucket but if I do
that and let me just run that real quick
um so if I wh
whoa let's just do this where did I
go there we go so if I take that and run
it
then it's going to take a
second I'm
assuming and then it's going to store my
file and that's probably where it's
taking a second I don't know how big
this thing is I'm actually creating I
probably should have looked at
that well what I'm running into is I've
got something that's getting me some
sort of weird link because I'm getting a
huge file which normally I would not get
so if I just
take
this
um see if this will
work it's still giving me a huge so
something is wrong with my
script if I look at
archive okay make archive directory
let's do this real
quick let's make sure we're getting this
right so the backup name that's the
directory let's make sure it's getting
this right so if I just
do let's do this
um
scripts so let's run that I'm going to
Archive I'm going to do
scripts there we go so something about
that slash it does not like so
instead I'm going to go so if I do do it
from here let's see if I do it from
here is that going to be
huge uh apparently it is so so there's
something about the number of files and
how it's pulling it in and honestly
that's okay um we can always fix that
yeah see this thing is like blowing up
super
big so that's something we can chase
down another time it's somehow grabbing
the wrong
folder uh yeah it just says dot so not
sure why it's running that uh why it's
running a problem but the bonus is you
can come in you can actually set up
your uh you can set up your script and
you
can use your dates you can actually pull
off some folders and or files and the
next thing you know you've got something
that's pretty nice and handy it is a
backup script but also one that you can
push stuff out to your buckets if you
want to out on out into your S3
buckets it's Tak me a little bit to get
through this one because of a couple
little bugs apologies for that hopefully
it's not an overly long or overly short
recording but now we've got our back
backup script we will come back next
time around and we'll have some new
stuff to talk through uh whether it's
python or something else we'll just sort
of see where we're going if you have any
questions shoot us an email at info@
develop andur go out there and have
yourself a great day a great week and we
will talk to you next
time well hello this is Rob from develop
andur building better developers and we
have a mastermind class that will be
starting or actually several Mastermind
classes starting in 2024 check us out at
technology Mastermind
204. we've got all the information you
need including some pricing early bird
discounts up to 50% off but those are
things that you're going to have to act
soon there is an application process so
go ahead and sign up today thanks a
[Music]
lot
Transcript Segments
0

[Music]

6.72

well hello and welcome back we are

9.92

wrapping up essentially this time our

12.08

little backup script and we're going to

14.12

walk through a couple last minute

15.48

cleanup things and deploy and we're to

18.199

talk about deploying a python script and

20.76

a couple little things we can do to help

22.6

ourselves out in the future now one of

25.119

the things that has sort of come

27.84

together is that we have got

30.519

um all of our little functions we built

32.399

now one of the things that we pulled

33.879

over this time around is uh we're going

36.879

to call it backup database oops I don't

39.6

need

40.76

that and uh we saw this in the prior one

43.559

where it's just a uh we just didn't pull

45.28

it into our backup script I don't think

48

and so what we've also

49.719

done it's just because we've got a you

52.199

know a lot of useful little things we've

54.199

now tweaked our script a little bit so

56.92

that it will allow us to we can use a um

61

a bucket

62.76

parameter and if we do that by itself

65.119

it's going to list the buckets that we

67.04

have uh connected for our account if we

69.68

do files and give it a bucket name then

72.759

it's going to list the files for that

74.36

bucket and then we've got of course our

77.04

other pieces we've also added dump which

80

gives us our data we give it a database

82.04

name and an output file so it would be

84.36

you know my database and you my

86.479

database.sql

87.92

and that one the dump is just going to

92.88

dump the file we could like we did with

96.52

our ZIP and store we could actually

99.84

upload our

101.28

file so if we

103.799

wanted uh let's see backup data base

106.36

let's just do that we'll just uh oh and

110.479

we can clean that we bring that over

112.439

this way a little bit so what we could

114.64

do here is we could say hey I'm going to

117.039

back up the database and then I'm going

119.399

to take take the out

124.079

file whatever output file is and I'm

126.799

going to send it to my bucket name but

128.28

then that means I've got to give it a

129.64

another bucket name so let's

131.64

not uh we'll save that for another time

135.319

uh actually what we could do

138.36

is yeah we'll leave it for now but

140.56

basically we could add another bucket

141.76

name and then send that out

143.8

or uh there's a couple different ways we

145.959

could do that for our backup database if

147.599

we wanted to keep it simple as number of

150.68

parameters then what we could do is

152.959

generate based on the database name we

155.2

could send a database in a bucket and

158.04

just do database.sql for output so we

161

don't have to send that file name in

164.48

anymore and then we could send it out to

166.8

a bucket but that's you know neither

169.68

here nor there that's some of the stuff

170.92

that you can do now so for example if we

174.36

do Python 3 Let's just show one real

176.64

quick uh bucket project is what we call

179.959

this and we're going to just call it

182.92

buckets if we do that then it's going to

185.36

list hey here's all of the buckets that

187.28

we have available if I want to take one

189.44

of those I don't even know what this

191.64

thing is let's see what this is uh that

194.56

one is going to be uh

199.4

files and then it's got a couple

201.36

different files there so it's got some

202.599

text files setting out

204.239

there obviously it's been sitting around

206.319

for a while too so that is our backup

210.319

script now what we can do let's open

212.319

this up a little bit more so I'm going

214.64

to go and I'm going to copy this script

217.159

out uh this is called bucket project and

220.76

I'm going to copy it out

225.959

to I'm going to SCP it there's a couple

228.4

ways you can do it but I'm going to SCP

229.76

this script out

231.319

to My Demo server and I'm going to do

235.319

I'm going go log into

237.04

that and so now if you look I've got my

240.959

bucket project there now what I'm going

242.48

to do is I'm going to try to run

245.4

that and this has got a thing called

247.76

shorty so let's start

250.239

with um let's do this let's do make uh

254.4

do I have a let me see if I have a

256.68

backup folder I do not so let's do this

259.84

I'm just going to do yeah I might do

262.32

that so I'm going to make something I'm

264.44

going to make a backup folder out on the

268.6

opt

270.6

and do something out

272.44

there and so let's just go ahead and

275

chod 777

282.72

that and I'm going to own it I'm to

285.639

change

289.039

that oops I need to pseudo

292.08

that so now this user owns that backup

296.8

so if I look I can see that on backup

299.24

I'm owning it I've got all the rights I

301

need so

303.28

now I'm going to go to backup

309.36

oh and I'm actually going to go ahead

311.68

and copy my script out here just because

313.919

just to keep it sort of clean so I'm

315.28

going to take

316.639

the uh bucket

319.28

project to here and then I'm going to

322.199

move that

324

to uh backup.

328.08

py so now I've got that so now I can try

331.919

to do Python 3 back up if I don't give

334.639

it anything then it's going to say hey I

337.319

don't have boto 3 so I need to do pip 3

340.199

install boto 3 we're going to look at

342.919

this in just a

345.56

second it's going to take it and we're

348.12

going to go ahead and we're going to

349.039

install that and we're going to try to

350.479

run it let's see what it

353.12

does now this one is going to probably

356.639

does not have Okay so that's l list out

359.8

of range so I don't have it any further

362.6

able to do that so let's just do buckets

364.52

I need to give it

368.72

something and so now I don't have my um

373.08

I don't have my AWS

376.68

installed so I'm going to need to do

378.96

that so I had to go through and install

381.88

my client on this guy so now when we run

384.759

it we can see here's my list of buckets

387.44

as we've seen before now one of things

389.72

we can do is that we can do a pip three

395.96

freeze and we can actually see all of

399.319

now this one's got a whole bunch of crap

400.68

but we can see all of the packages that

402.68

we have set up and so we can see for

404.72

example

405.639

boto3 photo core all that kind of stuff

408.16

so what we can do is we can take

410.639

this and if we do that into

415.199

requirements.

418.4

text

420.68

then one of the things we can do for an

421.919

install is uh to help us out is we can

424.12

do a pip 3

426.4

install with a-r give it the

428.68

requirements file and it will try to

430.16

install all of that stuff and now here

432.4

it's already satisfied because I've

433.599

already done it uh even though it looks

435.24

like it's picking a couple interesting

437.36

little versions along the way not sure

439.12

why it's doing

440.639

that but that's okay uh the bottom line

444.039

is is that makes it easier so we don't

446.12

have to like we just did run through an

448.479

install or run through run the project

450.96

or the application and then find out

453.28

that oh I'm missing all these

456.479

requirements we can just run it once

458.599

it's going to pick up whatever we're

459.68

missing and then we're off and running

461.759

otherwise it can get a little bit

463.08

tedious particularly when we're doing

464.919

things like uh like a Jango application

467.879

or something we've got a lot of

469

different things thrown in there or

471.199

there's some other things if you're

472.12

doing flask and some other uh python

474.28

projects that can get a little bit

476.72

complicated so now what we want to do is

479.72

one we're going to wait for this

481.52

to be done installing dependencies so we

484.36

can get through this little thing

485.759

apologies if that took a second but

487.84

that's okay I'll be right back when this

489.72

is done okay that took a long time I

492.56

apologize for that um let me clean up a

495.44

couple

497.08

things and so now what we've got is

499.24

we've got our little backup script so

501.759

what we would want to do in this case is

503.639

let's take uh let's just back up the

506.4

database so if we wanted to

508.24

do something complex I guess we could

511.319

have it like schedule we can just do our

513.68

very basic uh backup dump I think it's

517.959

lower I think it's uppercase and we're

520.159

just going to call it shorty.

523.68

SQL oops uh so I don't have

530.519

my I don't have my do my

534.36

config

538.2

so

540.519

and I probably need to clean up that

542.24

call in

568.12

there

578.56

three

581.92

two one so let me let's make sure I

585.079

don't have my user do I have Rob here

587.56

somewhere I don't okay so now I should

589.56

be able to

593.8

dump uh let's

598.12

see let's make sure I've got

604.2

it oh I did

606.76

not try one more

609.959

time nope that's why I don't have that

613.279

user set so if I set up my user properly

615.6

let me make sure I've got

619.44

him okay I do one second I need to

622.48

change my my

628.04

conf

650.639

3 2 1 okay so now that I've got it now

655.76

it will run now one of the things we can

657.56

do is we can actually scoll ripped this

660.519

so let's go

662.12

to uh we're going to make

667.36

scripts and we're going to do a

671.16

backup.

687.959

shell

712.399

three 2 one and so we're going to come

715.16

in here and we're going to create a

716.24

little script that's just going to do

717.399

Python 3 our backup

720

and we're going to call

722.44

this uh

724.8

shorty and we're going to give it this

727.36

it's going to give us our name so now

729.959

right it's going to give us a date so

732.12

what we can do here is if we chod plus X

735.44

the backup

736.839

script and then we do

741.519

um SLB

744.32

backup then if we go to our opt backup

750.32

what we see now is we've got our name

753.079

with us with the date in that and we

754.639

could also do it with time and such like

756.56

so that we can actually now we could

758.12

create a Cron job that runs us for

760.76

example every night at midnight and now

763.279

we've backed up our database now the

765.519

other thing we can do is if we want to

768.12

back up folders we could do the same

770.72

thing so I could do uh let me go back to

773.959

my home and let me go to my scripts and

777.399

what I can also do

781.88

well where did I put

783.88

that oops put that in the wrong place so

787.72

I'm going to put that to

790.48

scripts and so now if I go to scripts I

794.24

could also say I'm going to back up

798.6

my when I do this I also

806

want let me do this there we we go so

810.399

the same thing I can go back and I can

812.199

do opt

815.24

backup backup.

817.6

py and I can do uh what did I call that

821.44

I call

825.079

that uh where is where is the

831.04

see OH ZIP and store so

834.24

archive I called that

836.759

archive and so then I can take switch uh

839.72

let's see so I'm going to take my home

842.639

folder and I'm just going to call it uh

846.72

home let's do this demo 3 home.

853.56

zip and I think I also

859.24

need does that give me the bucket let's

861.959

see if I do

864.68

arive oh because it gives me a hardcoded

867.8

bucket name right now so I'm going to

869.079

change it well I'll leave that for now

871.199

so what I want to do is give it an extra

873.88

um give it something extra so I can give

876.399

it the right bucket but if I do

880.48

that and let me just run that real quick

884.6

um so if I wh

887.8

whoa let's just do this where did I

890.759

go there we go so if I take that and run

897.68

it

901.56

then it's going to take a

903.24

second I'm

905.399

assuming and then it's going to store my

909.16

file and that's probably where it's

911

taking a second I don't know how big

913

this thing is I'm actually creating I

915.04

probably should have looked at

916.68

that well what I'm running into is I've

919.6

got something that's getting me some

920.72

sort of weird link because I'm getting a

922.639

huge file which normally I would not get

927.6

so if I just

931.8

take

933.36

this

936.24

um see if this will

942.44

work it's still giving me a huge so

944.959

something is wrong with my

950.6

script if I look at

955.12

archive okay make archive directory

962.92

let's do this real

968.8

quick let's make sure we're getting this

971.199

right so the backup name that's the

979.92

directory let's make sure it's getting

982.04

this right so if I just

987.079

do let's do this

990.04

um

992.079

scripts so let's run that I'm going to

994.519

Archive I'm going to do

998.639

scripts there we go so something about

1001.199

that slash it does not like so

1006.68

instead I'm going to go so if I do do it

1009.639

from here let's see if I do it from

1011.92

here is that going to be

1015.56

huge uh apparently it is so so there's

1018.16

something about the number of files and

1020.24

how it's pulling it in and honestly

1023.079

that's okay um we can always fix that

1025.6

yeah see this thing is like blowing up

1027.36

super

1029.36

big so that's something we can chase

1031.72

down another time it's somehow grabbing

1033.6

the wrong

1035.24

folder uh yeah it just says dot so not

1038.199

sure why it's running that uh why it's

1040

running a problem but the bonus is you

1042.959

can come in you can actually set up

1045.959

your uh you can set up your script and

1050.6

you

1052.08

can use your dates you can actually pull

1054.799

off some folders and or files and the

1056.919

next thing you know you've got something

1058.24

that's pretty nice and handy it is a

1060.919

backup script but also one that you can

1063.32

push stuff out to your buckets if you

1065.36

want to out on out into your S3

1068.96

buckets it's Tak me a little bit to get

1070.96

through this one because of a couple

1072.6

little bugs apologies for that hopefully

1074.48

it's not an overly long or overly short

1076.72

recording but now we've got our back

1078.4

backup script we will come back next

1079.96

time around and we'll have some new

1081.52

stuff to talk through uh whether it's

1083.559

python or something else we'll just sort

1084.919

of see where we're going if you have any

1086.96

questions shoot us an email at info@

1089.2

develop andur go out there and have

1090.96

yourself a great day a great week and we

1093.2

will talk to you next

1096.2

time well hello this is Rob from develop

1098.84

andur building better developers and we

1101

have a mastermind class that will be

1102.76

starting or actually several Mastermind

1104.559

classes starting in 2024 check us out at

1107.32

technology Mastermind

1109.28

204. we've got all the information you

1111.36

need including some pricing early bird

1113.559

discounts up to 50% off but those are

1116.159

things that you're going to have to act

1117.799

soon there is an application process so

1120.76

go ahead and sign up today thanks a

1125.1

[Music]

1137.32

lot