-
Notifications
You must be signed in to change notification settings - Fork 0
/
en-internet-backup-restore-files-web-sql.html
366 lines (351 loc) · 44.2 KB
/
en-internet-backup-restore-files-web-sql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE HTML>
<!--
Twenty by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>How to backup and restore a website and its SQL database</title>
<link rel="alternate" type="application/rss+xml" href="https://silomia.github.io/rss.xml" title="Silomia">
<link rel="alternate" type="application/rss+xml" href="https://silomia.github.io/en-rss.xml" title="Silomia English">
<link rel="alternate" hreflang="fr" href="https://silomia.github.io/internet-sauvegarde-backup-restauration-web-sql.html">
<link rel="alternate" hreflang="en" href="https://silomia.github.io/en-internet-backup-restore-files-web-sql.html">
<link rel="canonical" href="https://silomia.gitlab.io/en-internet-backup-restore-files-web-sql.html">
<link rel="preload" href="css/styles.min.css" as="style">
<link rel="preload" href="js/script.min.js" as="script">
<link rel="preload" href="fonts/silomia-inter-light.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="fonts/silomia-inter-menu.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="fonts/silomia-inter-semibold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="fonts/silomia-symbol.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="apple-touch-icon" sizes="192x192" href="favicon-touch-192x192.png">
<link rel="icon" type="image/png" sizes="144x144" href="favicon.png">
<link rel="manifest" href="manifest.json">
<link rel="mask-icon" href="magnolia-silomia-carre.svg" color="#ab2bab">
<meta name="apple-mobile-web-app-title" content="Silomia">
<meta name="application-name" content="Silomia">
<meta name="theme-color" content="#ffffff">
<meta property="og:title" content="How to backup and restore a website and its SQL database">
<meta property="og:locale" content="en">
<meta property="og:site_name" content="Silomia">
<meta property="og:type" content="article">
<meta property="og:image" content="https://silomia.github.io/images/macbook-pro-clavier.jpg">
<meta property="og:url" content="https://silomia.github.io/en-internet-backup-restore-files-web-sql.html">
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=no">
<script type="application/ld+json">
{"@context":"http://schema.org/","@type":"Article","author":{"@type":"Person","name":"Ralph Davidovits"},"publisher":{"@type":"Organization","name":"Silomia","logo":{"@type":"ImageObject","url": "https://silomia.github.io/favicon-touch-192x192.png"}},
"datePublished":"2021-06-21","dateModified":"2024-07-15",
"headline":"How to backup and restore a website and its SQL database",
"image":["https://silomia.github.io/images/macbook-pro-clavier.jpg"],
"mainEntityOfPage":{"@type":"WebPage","@id":"https://silomia.github.io/internet.html"}
}
</script>
<style media="screen">@media screen and (prefers-color-scheme:dark){body{color:silver;background-color:#151515}}a,article,body,div,em,footer,header,html,img,li,picture,section,span,strong{margin:0;padding:0;border:0}h1,h2,h3,h4,p,ul{padding:0;border:0}article,footer,header,section{display:block}.container{margin-left:auto;margin-right:auto;width:1300px}*,.row,.row>*,::after,::before{box-sizing:border-box}.row{border-bottom:solid 1px transparent;margin:-50px 0-1px -50px}.row>*{float:left;padding:50px 0 0 50px}.row::after,.row::before{content:"";display:block;clear:both;height:0}.\34 u,.\34 u\$,.\36 u,.\38 u{width:33.3333333333%;clear:none;margin-left:0}.\36 u,.\38 u{width:50%}.row.\31 50\%>*{padding:75px 0 0 75px}.row.\31 50\%{margin:-75px 0-1px -75px}.\38 u{width:66.6666666667%}body{font-family:"Inter",-apple-system,system-ui,sans-serif;font-weight:300;letter-spacing:.02em;line-height:1.65em}a{text-decoration:none;border-bottom:dotted 1px}h1,h2,h3,h4,strong{font-weight:600}em{font-style:italic}blockquote,p,ul{margin:0 0 2em}h1,h2,h3,h4{color:inherit;line-height:1.75em;margin:.7em 0;text-transform:uppercase;letter-spacing:normal}h1{font-size:1.4em}h2,h3{font-size:1.15em}blockquote{font-style:italic;padding:1em 0 1em 2em}body,section{font-size:14pt}section.special{text-align:center}header.major{padding-bottom:2em}header.special{margin-bottom:4em;padding-top:5.5em;position:relative;text-align:center}header.special::after,header.special::before{border-bottom:solid 1.5px;border-top:solid 1.5px;content:"";height:7px;opacity:.1;position:absolute;top:1.75em;width:43%}header.special::before{left:0}header.special::after{right:0}header.special h1{margin-bottom:0;font-weight:300}header.special h1+p{margin-bottom:0;padding-top:1.5em}header.special .icon{height:7em;left:0;position:absolute;text-align:center;top:1em;width:100%}header.special .icon::before{font-size:3.5em;opacity:.35}footer>:last-child{margin-bottom:0}picture{min-height:100px}#main{padding:7em 0}body.index #main{padding-top:5em}.mh-head .mh-text{display:block}.mh-head.mh-align-right .mh-text{text-align:right}.image.featured img,picture.image.featured{display:block;margin:0 0 2em;width:100%;min-height:200px}.wrapper{margin-bottom:5em;padding:5em}.wrapper.style3,.wrapper.style4{color:inherit;border-radius:5px}.wrapper.style4{padding:4em}.fa-lg{font-size:1.33333333em;line-height:.75em;vertical-align:-15%}.icon{text-decoration:none;position:relative}.icon::before{font-style:normal;font-weight:400;text-transform:none!important}.mm-menu_offcanvas:not(.mm-menu_opened){display:none}@media screen and (min-width:1900px){.container{width:1400px}body,section{font-size:16pt}}@media screen and (max-width:1680px){.container{width:1200px}.row>*{padding:40px 0 0 40px}.row{margin:-40px 0-1px -40px}.row.\31 50\%>*{padding:60px 0 0 60px}.row.\31 50\%{margin:-60px 0-1px -60px}#main .sidebar section{margin:3em 0 0;padding:3em 0 0}#main .sidebar section:first-child{border-top-width:0;padding-top:0;margin-top:0}body{font-size:14pt}section{font-size:12.5pt}}@media screen and (max-width:1280px){.container{width:960px}.row>*{padding:40px 0 0 40px}.row{margin:-40px 0-1px -40px}.row.\31 50\%>*{padding:60px 0 0 60px}.row.\31 50\%{margin:-60px 0-1px -60px}#main .sidebar section{margin:3em 0 0;padding:3em 0 0}#main .sidebar section:first-child{border-top-width:0;padding-top:0;margin-top:0}body{font-size:13pt;line-height:1.65em}section{font-size:12pt}h1,h2,h3,h4{line-height:1.5em}.wrapper{margin-bottom:4em;padding:4em 3em}.wrapper.style4{padding:3em}}@media screen and (max-width:980px){.container{width:95%}.row>*{padding:30px 0 0 30px}.row{margin:-30px 0-1px -30px}.row.\31 50\%>*{padding:45px 0 0 45px}.row.\31 50\%{margin:-45px 0-1px -45px}body{font-size:13pt;line-height:1.55em}section{font-size:12.5pt}header.special{padding-left:2.5em;padding-right:2.5em}.wrapper{margin-bottom:3em;padding:3em 2.5em}.wrapper.style4{padding:2.5em}}@media screen and (max-width:840px){.container{width:95%!important}.row>*{padding:30px 0 0 30px}.row{margin:-30px 0-1px -30px}.row.\31 50\%>*{padding:45px 0 0 45px}.row.\31 50\%{margin:-45px 0-1px -45px}.\31 2u\28narrower\29 {width:100%;clear:none;margin-left:0}body,html{font-size:14pt}section{font-size:13pt;margin:1em 0}h1{font-size:1.25em;letter-spacing:-.02em}h2,h3{font-size:1.05em;letter-spacing:.002em}header.special{margin-bottom:4em;padding-top:5em}header.special::after,header.special::before{width:40%}header.special h1+p{padding-top:1.25em;letter-spacing:-.01em}section:first-child{margin-top:0}.wrapper.style4{padding-bottom:3em}#main{padding:5em 0}}@media screen and (max-width:730px){.container{width:100%!important}.row>*{padding:30px 0 0 30px}.row{margin:-30px 0-1px -30px}.row.\31 50\%>*{padding:45px 0 0 45px}.row.\31 50\%{margin:-45px 0-1px -45px}body{min-width:320px;font-size:14pt;letter-spacing:.01em}section{font-size:13.5pt}h1{font-size:1.25em}h2,h3{font-size:1em}header,header p{text-align:center}header.special{margin-bottom:3em;padding-left:1.5em;padding-right:1.5em}header.special::after,header.special::before{width:38%}header.special .icon{font-size:.75em;top:1.5em}.image.featured img,picture.image.featured{min-height:100px}.wrapper{margin-bottom:2.5em;padding:2.25em 1.5em}.wrapper.style4{background-size:10em;padding:1.5em 1.5em 3em}#main{padding:3.5em 0 2.5em}}@media screen and (max-width:360px){body{font-size:14pt}section{font-size:13pt}}</style>
</head>
<body class="right-sidebar" onerror="ers()">
<div id="page-wrapper">
<!-- Header -->
<header id="header" role="banner" class="mh-head mh-align-right">
<span class="mh-btns-left"><a class="mburger mburger--squeeze" href="#my-menu"><b></b> <b></b> <b></b> <span class="mburger-label">Menu</span></a></span>
<span class="icon fa-magnolia mh-logo"></span>
<span class="mh-text slogan"><strong>Touch the light</strong> through the path of words</span>
</header>
<!-- Main -->
<article id="main">
<header class="special container">
<span class="icon fa-code"></span>
<h1><strong>Method for backing up and restoring</strong> a web site and its SQL database</h1>
<p>Reboot a website in less than an hour.</p>
</header>
<!-- One -->
<section class="wrapper style4 container">
<div class="row 150%">
<div class="8u 12u(narrower)">
<!-- Content -->
<div class="content">
<section>
<picture class="image featured">
<source type="image/avif" media="(max-width: 415px)" srcset="images/macbook-pro-clavier@1x.avif">
<source type="image/avif" media="(min-width: 416px)" srcset="images/macbook-pro-clavier@1x.avif 1x, images/macbook-pro-clavier.avif 2x">
<source media="(max-width: 415px)" srcset="images/macbook-pro-clavier@1x.jpg">
<source media="(min-width: 416px)" srcset="images/macbook-pro-clavier@1x.jpg 1x, images/macbook-pro-clavier.jpg 2x">
<img src="images/macbook-pro-clavier@1x.jpg" alt="Clavier lumineux Macbook Pro">
</picture>
<header>
<h2><span class="icon fa-map-marker fa-lg"></span> Backing up your website and SQL database (Part 1)</h2>
</header>
<p>As with your computer, keeping a backup copy of your website is imperative.</p>
<h3>1- Prepare the backup of the website:</h3>
<p>Always have a copy of your website on your computer. If you have installed a blog, forum, cms, e-commerce, keep an operational copy with the config, htaccess, plug-ins, additional modules, themes, templates and your modifications.</p>
<p>If you update your web software, do the same with your backup.<br>
If your site contains an upload folder and logs, go get them regularly. To simplify this last task, the script below will make a ZIP backup of a log file. Instead of downloading a hundred small text files, everything will be grouped in a ZIP file.</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #BC7A00"><?php</span>
<span style="color: #408080; font-style: italic">/* Make sure that the backup destination folder is created. It can be either in the www folder or elsewhere. Here we put it somewhere else*/</span>
<span style="color: #408080; font-style: italic">/* Modify your settings */</span>
<span style="color: #19177C">$uploads</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"/home/loginftp/www/uploads"</span>; <span style="color: #408080; font-style: italic">/* absolute path of the uploads folder to save without the / final */</span>
<span style="color: #19177C">$repsauvegarde</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"/home/loginftp/sauvegarde/"</span>; <span style="color: #408080; font-style: italic">/* absolute path to the backup directory */</span>
<span style="color: #19177C">$zipuploads</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"mesuploads"</span>; <span style="color: #408080; font-style: italic">/* name of the zip file of the backup without putting the .zip at the end */</span>
<span style="color: #408080; font-style: italic">/* We are going to put 2 different folders in one zip file. */</span>
<span style="color: #408080; font-style: italic">/* Modify your settings */</span>
<span style="color: #19177C">$logs1</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"/home/loginftp/www/telechargement/logs"</span>; <span style="color: #408080; font-style: italic">/* absolute path to the logs of downloads directory to be saved without the / final */</span>
<span style="color: #19177C">$logs2</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"/home/loginftp/www/session/logs"</span>; <span style="color: #408080; font-style: italic">/* absolute path to the session logs folder to be saved without the / final */</span>
<span style="color: #19177C">$repsauvegarde</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"/home/loginftp/sauvegarde/"</span>; <span style="color: #408080; font-style: italic">/* absolute path to the backup directory */</span>
<span style="color: #19177C">$ziplogs</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"meslogs"</span>; <span style="color: #408080; font-style: italic">/* name of the zip file of the backup without putting the .zip at the end */</span>
<span style="color: #408080; font-style: italic">/* That is it. Place this file by FTP somewhere on your web server, in a discreet location. */</span>
<span style="color: #408080; font-style: italic">/* Then open it with your web browser and follow the instructions. */</span>
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"<html><body>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"1. This script automatically creates a backup of the folder </span><span style="color: #BB6688; font-weight: bold">$uploads</span><span style="color: #BA2121"> </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"The folder is being backed up.......</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"zip -qr -5 </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde$zipuploads</span><span style="color: #BA2121"> </span><span style="color: #BB6688; font-weight: bold">$uploads</span><span style="color: #BA2121">"</span>));
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"C'est fait. </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"2. Backup of folders </span><span style="color: #BB6688; font-weight: bold">$logs1</span><span style="color: #BA2121"> and </span><span style="color: #BB6688; font-weight: bold">$logs2</span><span style="color: #BA2121"> </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"Folders are being backed up.......</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"zip -qr -5 </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde$ziplogs</span><span style="color: #BA2121"> </span><span style="color: #BB6688; font-weight: bold">$logs1</span><span style="color: #BA2121">"</span>));
<span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"zip -qr -5 </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde$ziplogs</span><span style="color: #BA2121"> </span><span style="color: #BB6688; font-weight: bold">$logs2</span><span style="color: #BA2121">"</span>));
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"It is over. You can fetch the FTP backup in the folder </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde</span><span style="color: #BA2121"> .</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>Don't forget to delete these files from your server via FTP as they may contain passwords or personal information.</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></body></html>"</span>;
<span style="color: #BC7A00">?></span>
</pre></div>
<p><strong>Use Tar, GZIP or BZ2 instead of ZIP.</strong> There is a difference between tar and zip: there is a limit to combining several different folders in the same archive. With tar, you can only compress one directory with its sub-folders or combine several tar archives. So, for my example backup script we can replace line 20:</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"zip -qr -5 </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde$zipuploads</span><span style="color: #BA2121"> </span><span style="color: #BB6688; font-weight: bold">$uploads</span><span style="color: #BA2121">"</span>));
</pre></div>
<p>by this for the Tar Gzip:</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"tar -czf </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde$zipuploads</span><span style="color: #BA2121">.tar.gz </span><span style="color: #BB6688; font-weight: bold">$uploads</span><span style="color: #BA2121">"</span>));
</pre></div>
<p>or this for the Tar Bzip2:</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"tar -cjf </span><span style="color: #BB6688; font-weight: bold">$repsauvegarde$zipuploads</span><span style="color: #BA2121">.tar.bz2 </span><span style="color: #BB6688; font-weight: bold">$uploads</span><span style="color: #BA2121">"</span>));
</pre></div>
<p>Note that tar bzip2 compresses better than tar gzip, which is also often more effective than Zip.</p>
<p><strong>ATTENTION:</strong> don't try to make a ZIP file of all your hosting, it might not work. There are 2 reasons for this: the execution time of a script is often limited from 30 to 120 seconds and the RAM memory allocated to processing the script and handling the files is limited depending on your hosting offer (from 32 MB to 256 MB, which is insufficient for a backup of your website). To know these limits, create a file info.php with the following code</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #BC7A00"><?php</span>
<span style="color: #008000">phpinfo</span>();
<span style="color: #BC7A00">?></span>
</pre></div>
<p>Send this file by FTP, open it with your web browser, and look for the lines <em>max_execution_time</em> (script execution time), <em>memory_limit</em> and <em>post_max_size</em> to know the maximum size of the file that can be processed.</p>
<h3>2- Preparing the MySQL database backup</h3>
<p>Backing up the MySQL database is called a “dump”. It can be done from your phpMyadmin interface, or from a php script.</p>
<h4>a) Backup with PHP Script</h4>
<p>The advantage of backing up by PHP script is its speed and the ability to control some options that can't be managed with phpMyadmin, in particular the problem of encoding accented characters (called character set). This is why I prefer this solution.</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #BC7A00"><?php</span>
<span style="color: #408080; font-style: italic">/* Modify your MySQL settings */</span>
<span style="color: #19177C">$db_server</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"ServeurMySQL"</span>;
<span style="color: #19177C">$db_name</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"NomDeLaBaseSQL"</span>;
<span style="color: #19177C">$db_username</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"IdentifiantSQL"</span>;
<span style="color: #19177C">$db_password</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"MotDePasseSQL"</span>;
<span style="color: #19177C">$db_charset</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"utf8"</span>; <span style="color: #408080; font-style: italic">/* put utf8 or latin1 */</span>
<span style="color: #408080; font-style: italic">/* That is it. Place this file by FTP somewhere on your web server, in a discreet location. */</span>
<span style="color: #408080; font-style: italic">/* Then open it with your web browser and follow the instructions. */</span>
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"<html><body>This script creates a backup of the database with the character set encoding </span><span style="color: #BB6688; font-weight: bold">$db_charset</span><span style="color: #BA2121"> . </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>The backup file is in the same place as this script. </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"Your database is being backed up.......</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">if</span> (<span style="color: #008000">system</span>(<span style="color: #BA2121">"mysqldump --host=</span><span style="color: #BB6688; font-weight: bold">$db_server</span><span style="color: #BA2121"> --user=</span><span style="color: #BB6688; font-weight: bold">$db_username</span><span style="color: #BA2121"> --password=</span><span style="color: #BB6688; font-weight: bold">$db_password</span><span style="color: #BA2121"> -C -Q -e --default-character-set=</span><span style="color: #BB6688; font-weight: bold">$db_charset</span><span style="color: #BA2121"> </span><span style="color: #BB6688; font-weight: bold">$db_name</span><span style="color: #BA2121"> | gzip -c > </span><span style="color: #BB6688; font-weight: bold">$db_name</span><span style="color: #BA2121">-</span><span style="color: #BB6688; font-weight: bold">$db_charset</span><span style="color: #BA2121">.sql.gz"</span>));
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>"</span>;
<span style="color: #008000; font-weight: bold">echo</span> <span style="color: #BA2121">"It is over. You can fetch the backup file. It is called: <a href=</span><span style="color: #BB6622; font-weight: bold">\"</span><span style="color: #BB6688; font-weight: bold">$db_name</span><span style="color: #BA2121">-</span><span style="color: #BB6688; font-weight: bold">$db_charset</span><span style="color: #BA2121">.sql.gz</span><span style="color: #BB6622; font-weight: bold">\"</span><span style="color: #BA2121">></span><span style="color: #BB6688; font-weight: bold">$db_name</span><span style="color: #BA2121">-</span><span style="color: #BB6688; font-weight: bold">$db_charset</span><span style="color: #BA2121">.sql.gz</a> (right-click, and save as... or save the link target as...) </span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br>Don't forget to delete this file from your server via FTP as it contains passwords.</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BA2121"><br></body></html>"</span>;
<span style="color: #BC7A00">?></span>
</pre></div>
<h4>b) Backup by phpMyadmin</h4>
<p>To make a backup of your current MySQL database connect to your phpMyadmin interface. Enter the name of the SQL database and its password, then at the top of the left column, click on the name of the database. At the top of the central page, click on the “Export” tab. The Export page displays a simplified version that should be sufficient most of the time. Choose to export in SQL format and click on the Run button. To select specific tables, choose the custom method and check the boxes of the tables you want to export. Save the output to a file, with a character set that should be UTF-8 by default, and if the database is large, you can compress it to GZIP format. The other default checkboxes should be acceptable, unless you know what you are doing, and then click the Run button. And don't forget to log out when you are done by clicking on the Log Out icon in the top left corner.</p>
<p>After the backup, the recovery…</p>
<hr>
<header>
<h2><span class="icon fa-map-marker fa-lg"></span> Restoring your website and SQL database (Part 2)</h2>
</header>
<h3>3- Restoring the website</h3>
<p>This is easy. First of all, if you have changed the file permissions to 404 or 444 and folder to 505 or 555 as <a href="en-internet-secure-protect-from-hacker-attacks.html#chmod">explained in the article</a>, you will not be able to delete or replace them. Redo the commands by giving permission 604 or 644 to files and 705 or 755 to folders. Then completely erase your website. You don't know what traces and hidden files the hacker has left, you have to rebuild on a sound basis. Then, by FTP send your backup to your site. Then change the file and folder permission as mentioned above.</p>
<h3>4- Restoring the SQL database</h3>
<p>If your backup is up to date, you have peace of mind. If your site is very active and too much time has passed between your last backup and the hacking, make a backup of the week-old database as explained above. However, you will not be sure that this database is healthy.</p>
<h4>a) Restoring by phpMyadmin</h4>
<p>Unlike backup, restoring via phpMyadmin has a limit on the maximum upload file size. This size varies depending on your hosting plan from 16 to 64 MB most of the time. To find out this limit, create a file info.php with the following code</p>
<span class="smallfont">Code PHP</span>
<!-- HTML generated using hilite.me --><div class="smallfont code" style="overflow:auto;width:auto;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #BC7A00"><?php</span>
<span style="color: #008000">phpinfo</span>();
<span style="color: #BC7A00">?></span>
</pre></div>
<p>Send this file by FTP, open it with your web browser, and look for the line <em>upload_max_filesize</em> to know the maximum size. If your MySQL backup is below this limit, you can do it.</p>
<p>A tip if your “dump” or backup was done with phpMyadmin, you can restore in the same way, otherwise, go to the PHP scripting method explained in the next section.</p>
<p><em>Deleting the SQL database</em><br>
Login to your phpMyadmin interface, enter the name of the SQL database and its password, then at the top of the left column, click on the name of the database. Then in the main window, at the bottom of the page, under the checkboxes column, click on “Check all” and in the menu that follows, choose “Delete table”. Confirm the deletion of “Tables” by clicking on “Yes”.</p>
<p><em>Restoring the base</em><br>
You will import the new database. Click on the “Import” tab. Click on “Browse” to select the backup on your computer. <strong> WARNING:</strong> if the backup has just been made with phpMyadmin, i.e., having followed the procedure described above, select the character set “utf8” (there is a good chance that this character set is the right one, otherwise take “latin1”). If the backup was made otherwise, select the corresponding character set. Otherwise, accented characters will not display well on the website. Click Run. And don't forget to log out once you are done by clicking on the Log Out icon.</p>
<h4>b) Recovery by PHP script</h4>
<p>If you have exceeded the limit because your SQL database is too big, an excellent script can help you, it is called <a href="http://www.ozerov.de/bigdump.php">BigDump</a> of which you can download the latest <a href="depot/bigdump.zip">version 0.36b here</a>. The interface is in English. You just have to enter the parameters of your SQL database and choose the right character set “utf8” or “latin1”. If you used the above backup script, you know which character set you used, whereas you are less sure with phpMyadmin.</p>
<p><em>Deleting the SQL database</em><br>
Login to your phpMyadmin interface, enter the name of the SQL database and its password, then at the top of the left column, click on the name of the database. Then in the main window, at the bottom of the page, under the checkboxes column, click on “Check all” and in the menu that follows, choose “Delete table”. Confirm the deletion of “Tables” by clicking on “Yes”. And don't forget to log out when you are done by clicking on the Log Out icon.</p>
<p><em>Restoring the base</em><br>
By FTP, send bigdump.php and your SQL backup in the same folder. With your web browser, open bigdump.php, it should list your database. Then click on Start Import. Usually, everything should go well and a window should tell you that the database has been restored. Otherwise, you will have to make a backup table by table of your SQL database to reduce the size of the files. Just do it with phpMyadmin as explained above. If this is not enough, check the forums, there are many tips. Then by FTP, delete bigdump.php and the SQL backup. Never keep bigdump, a hacker could use it very easily to control your website.<br>
<em>A tip</em>, check how accented characters are displayed on your website after restoration. Because of some inconsistencies between latin1 and utf8, we can have bad surprises. For example, I have a blog where everything is in utf-8 (text, html charset, SQL interclass in utf-8, etc.), everything is consistent since its creation. If I make a dump (backup) of the database in utf8 with my script, then a restore with bigdump.php in utf8, the website doesn't display accented characters well. I had to do a dump in latin1 then restore with bigdump.php in utf8 to get back to normal. Think about it.</p>
<h3>5- Summary. You have on your computer</h3>
<p>a) your complete website (HTML files, images, and other files),<br>
b) all updated files of your blog, forum, cms, e-commerce with config, htaccess, plugins, modules, themes, templates and your modifications,<br>
c) the upload folders, logs, etc. that you regularly update,<br>
d) a recent backup of your MySQL database.</p>
<h3>6- If you are doing the restoration after a hack</h3>
<p>Change your FTP and MySQL passwords. Then, don't forget to edit the config.inc.php or equivalent files that need your new SQL password.</p>
</section>
</div>
</div>
<div class="4u 12u(narrower)">
<!-- Sidebar -->
<div class="sidebar" role="complementary">
<section>
<header>
<h2><span class="icon fa-talk fa-lg"></span> Comment</h2>
</header>
<p>These code snippets will help you save your website in case of data erasure, corruption, hacking, and when the only solution is to reinstall everything. Don't think that it never happens. It is a matter of time and statistics, it will happen. So have a backup plan like this.</p>
</section>
<section>
<header>
<h2><span class="icon fa-users fa-lg"></span> Share</h2>
</header>
<ul class="icons center">
<li><a href="#dmodale" id="omodale" class="icon circle fa-partage-alt"><span class="label">Lien</span></a></li>
<li><a href="mailto:?subject=Check%20out%20this%20article%20from%20the%20Silomia%20website.&body=I%20just%20read%20this%20article%20from%20the%20Silomia%20website%20and%20I%20think%20you%20will%20find%20it%20interesting.%20%20%0D%0Go%20to%20this%20address%3A%20https%3A%2F%2Fsilomia.github.io%2Fen-internet-backup-restore-files-web-sql.html" class="icon circle fa-envelope"><span class="label">E-mail</span></a></li>
</ul>
<ul class="icons center">
<li><a href="internet-sauvegarde-backup-restauration-web-sql.html" class="icon circle fa-language"><span class="label">Lien</span></a> <br><a class="smallfont" href="internet-sauvegarde-backup-restauration-web-sql.html">Version française</a></li>
</ul>
<dialog id="dmodale">
<header class="tmodale"><p>Copy the link to share it</p></header>
<p class="smallfont"><a id="lmodale" href="https://silomia.github.io/en-internet-backup-restore-files-web-sql.html">https://silomia.github.io/en-internet-backup-restore-files-web-sql.html</a></p>
<footer class="tmodale smallfont"><button id="cmodale" class="button">Close</button> <button id="copier" data-copie=">> Link copied" class="button special">Copy</button></footer>
</dialog>
</section>
</div>
</div>
</div>
</section>
<!-- Two -->
<section class="wrapper style1 container special">
<div class="row">
<div class="4u 12u(narrower)">
<section>
<span class="icon featured fa-child"></span>
<header>
<h3>“If-” you'll be a Man…</h3>
</header>
<p>Re-discover Rudyard Kipling's famous poem “If- you'll be a Man, my son” which has inspired so many generations. It celebrates the courage to overcome hardship.</p>
<footer>
<ul class="buttons">
<li><a href="en-if-you-will-be-a-man-my-son.html" class="button small">Read More</a></li>
</ul>
</footer>
</section>
</div>
<div class="4u 12u(narrower)">
<section>
<span class="icon featured fa-trophy"></span>
<header>
<h3>I've decided to succeed</h3>
</header>
<p>I have put together 10 tried and tested tips for finding the will to successfully achieve your ambitions and overcome obstacles in your personal and professional life.</p>
<footer>
<ul class="buttons">
<li><a href="en-change-your-life-succeed-evolve.html" class="button small">Read More</a></li>
</ul>
</footer>
</section>
</div>
<div class="4u 12u(narrower)">
<section>
<span class="icon featured fa-food"></span>
<header>
<h3>Gourmet treats</h3>
</header>
<p>Exquisite recipes for mini-cakes (madeleines, financiers, biscuits, cakes, muffins) and other delicacies (croissants, brioche, traditional cakes…).</p>
<footer>
<ul class="buttons">
<li><a href="en-delicacy.html" class="button small">Read More</a></li>
</ul>
</footer>
</section>
</div>
</div>
</section>
</article>
<!-- Menu -->
<nav id="my-menu" role="navigation">
<!--z><div id="menu" class="wrapper style3 container 75%"><h2>MENU</h2></z-->
<ul>
<li><a href="en-index.html"><span class="icon fa-home fa-fw"></span> Home</a></li>
<li><a href="en-if-you-will-be-a-man-my-son.html"><span class="icon fa-child fa-fw"></span> If- You'll Be a Man my Son</a></li>
<li><a href="en-change-your-life-succeed-evolve.html"><span class="icon fa-trophy fa-fw"></span> I've Decided to Succeed</a></li>
<li><a href="en-change-the-world-and-humanity.html"><span class="icon fa-baton-lumiere fa-fw"></span> Free Yourself from Evil</a></li>
<li><a href="en-universal-meditation-relaxation-video.html"><span class="icon fa-cloud fa-fw"></span> Relaxation and Meditation</a></li>
<li><a href="en-manipulation-crowd-social-opinion.html"><span class="icon fa-flag fa-fw"></span> Manipulate Opinion</a></li>
<li class="submenu">
<span><span class="icon fa-food fa-fw"></span> Gourmet Treats</span>
<ul>
<li><a href="en-mini-cake-madeleine.html"><span class="icon fa-food fa-fw"></span> Madeleines</a></li>
<li><a href="en-mini-cake-financier.html"><span class="icon fa-food fa-fw"></span> Almond Financiers</a></li>
<li><a href="en-mini-cake-butter-biscuits.html"><span class="icon fa-food fa-fw"></span> Butter Biscuits</a></li>
<li><a href="en-mini-cake-british.html"><span class="icon fa-food fa-fw"></span> Mini Cakes</a></li>
<li><a href="en-mini-cake-muffins.html"><span class="icon fa-food fa-fw"></span> Muffins</a></li>
<li><a href="en-mini-cake-bricks.html"><span class="icon fa-food fa-fw"></span> Bricks</a></li>
<li><a href="en-delicacy-croissants-pastry.html"><span class="icon fa-food fa-fw"></span> Croissants</a></li>
<li><a href="en-delicacy-brioche-pastry.html"><span class="icon fa-food fa-fw"></span> Brioche</a></li>
<li><a href="en-cake-tender-tere-couque.html"><span class="icon fa-food fa-fw"></span> Tender Cake / Tère Couque</a></li>
<li><a href="en-delicacy-pancakes-crepes.html"><span class="icon fa-food fa-fw"></span> Pancakes</a></li>
<li><a href="en-delicacy-caramel-salted-butter.html"><span class="icon fa-food fa-fw"></span> Caramel Salted Butter</a></li>
<li><a href="en-delicacy-hazelnut-chocolate-spread.html"><span class="icon fa-food fa-fw"></span> Hazelnut Chocolate Spread</a></li>
<li><a href="en-cake-amankay-apple-pie.html"><span class="icon fa-food fa-fw"></span> Amankay Apple Pie</a></li>
<li><a href="en-cake-streusel-cream-cherry.html"><span class="icon fa-food fa-fw"></span> Streusel and Cream</a></li>
<li><a href="en-cake-viennese-apple-strudel.html"><span class="icon fa-food fa-fw"></span> Apple Strudel</a></li>
<li><a href="en-cake-kouglof-gugelhupf.html"><span class="icon fa-food fa-fw"></span> Kouglof</a></li>
<li><a href="en-cake-stollen.html"><span class="icon fa-food fa-fw"></span> Stollen</a></li>
<li><a href="en-cake-rolled.html"><span class="icon fa-food fa-fw"></span> Rolled Cake</a></li>
<li><a href="en-cake-strawberry-pie.html"><span class="icon fa-food fa-fw"></span> Strawberry Pie</a></li>
<li><a href="en-cake-rhubarbe.html"><span class="icon fa-food fa-fw"></span> Rhubarb Pie</a></li>
<li><a href="en-cake-clafoutis.html"><span class="icon fa-food fa-fw"></span> Clafoutis</a></li>
<li><a href="en-cake-universal-pie.html"><span class="icon fa-food fa-fw"></span> Universal Pie</a></li>
<li><a href="en-cake-mirabelle-quetsche.html"><span class="icon fa-food fa-fw"></span> Mirabelle Cake</a></li>
<li><a href="en-cake-poppy-seed.html"><span class="icon fa-food fa-fw"></span> Poppy Seed Cake</a></li>
<li><a href="en-delicacy-rice-pudding-semolina.html"><span class="icon fa-food fa-fw"></span> Rice Pudding</a></li>
</ul>
</li>
<li><a href="en-business-model-canvas-validate-idea.html"><span class="icon fa-line-chart fa-fw"></span> Business Idea Canvas</a></li>
<li><a href="en-10-marketing-techniques-innovation.html"><span class="icon fa-shopping-cart fa-fw"></span> 10 Marketing Secrets</a></li>
<li><a href="en-blog-of-jokes.html"><span class="icon fa-paw fa-fw"></span> Blog of Jokes</a></li>
<li class="submenu">
<span><span class="icon fa-code fa-fw"></span> Tools for WebDev</span>
<ul>
<li><a href="en-internet-secure-protect-from-hacker-attacks.html"><span class="icon fa-code fa-fw"></span> Protected from hackers</a></li>
<li><a href="en-internet-backup-restore-files-web-sql.html"><span class="icon fa-code fa-fw"></span> Website Backup</a></li>
<li><a href="en-internet-seo-web-site.html"><span class="icon fa-code fa-fw"></span> Website SEO</a></li>
<li><a href="en-internet-debug-php-mysql.html"><span class="icon fa-code fa-fw"></span> Scripts Debugging</a></li>
</ul>
</li>
<li><a href="en-photography-practical-tips.html"><span class="icon fa-diaph fa-fw"></span> Photographer's Tips</a></li>
<li><a href="en-free-downloads.html"><span class="icon fa-download fa-fw"></span> Free Downloads</a></li>
<li><a href="en-message.html"><span class="icon fa-envelope fa-fw"></span> Contact</a></li>
<li><a href="#0" class="commutateur mode-clair" data-stylesheet="css/styles.clair.min.css"><span class="icon fa-sun fa-fw modestyle clair"></span> <span class="paramBouton">Light</span></a><a href="#0" class="commutateur mode-sombre" data-stylesheet="css/styles.sombre.min.css"><span class="icon fa-moon fa-fw modestyle sombre"></span> <span class="paramBouton">Dark</span></a> <a href="#0" id="modecaractopti"><span class="icon fa-font fa-fw modestyle sombre"></span></a></li>
</ul>
<!--z></div></z-->
</nav>
<!-- Footer -->
<footer id="footer" role="contentinfo">
<ul class="copyright">
<li><a href="en-index.html"><span class="icon fa-home fa-fw"></span> Home</a></li>
<li><a href="en-message.html"><span class="icon fa-envelope fa-fw"></span> Contact</a></li>
<li><a href="internet-sauvegarde-backup-restauration-web-sql.html"><span class="icon fa-language fa-fw"></span> En Français</a></li>
<li><a href="en-sitemap.html" accesskey="3"><span class="icon fa-align-bars fa-fw"></span> Site Map <span class="smallfont">[KEY]+3</span></a></li>
</ul>
<ul class="copyright">
<li>© 2007 to 2024 </li><li><a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></li><li><span class="icon fa-code fa-fw"></span> <a href="README.html">Credits</a></li>
</ul>
</footer>
<!--z><style>li.submenu{margin-top:1em}li.submenu ul{padding-left:.68em}#header{position:absolute}</style></z-->
</div><!-- page-wrapper -->
<!-- Scripts -->
<link rel="stylesheet" href="css/styles.min.css">
<link rel="stylesheet" id="feuillestyle-active"><link rel="stylesheet" id="feuilleStyleCaract">
<script src="js/script.min.js" async></script>
<script async>function ers(){var e=document.getElementById("page-wrapper").innerHTML.replace(/(<!--z>|<\/z-->)/g,"");document.getElementById("page-wrapper").innerHTML=e}try{eval("(class Foo{})")}catch(a){ers()}</script>
</body>
</html>