vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Programming Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=188)
-   -   Backup/restore using phpMyAdmin/SSH (https://vborg.vbsupport.ru/showthread.php?t=106935)

Snake 02-01-2006 10:00 PM

Backup/restore using phpMyAdmin/SSH
 
Backing Up & Restoring a MySQL Database using phpMyAdmin / SSH
================================================== =====

This is just a short mini-tutorial explaining how to backup parts of the mySQL database using phpMyAdmin and also via SSH (Secure Shell) access. This tutorial should be of use to most people, as it's an important part of any website/forum maintenance.

So, let's get started...

Step 1 - Backing up using phpMyAdmin

Note: Most good hosts provide phpMyAdmin (mySQL administration). If you do not know where it is or even if it exists on your server, just get in touch with your host.
  1. Login to phpMyAdmin.
  2. Select the database you wish to use.
  3. On the navigation bar on the top, select "Export" (besides SQL, Structure, Search, Query... etc.)
  4. You should now be presented with a nifty little page which shows all the tables in the database, SQL Options and Save Types. *
  5. To backup the whole database, click "Select All" under the list of tables in the page.
  6. To backup a selected few, just hold down CTRL on your keyboard and select the tables you wish to backup (release the key when all selecting is done).
  7. SQL Options can be left as default, but I suggest ticking the "Add DROP TABLE" option as if you are restoring a backup on a database that already exists and has the table in it - you will get a lot of errors! This way, by ticking the "Add DROP TABLE" option you will avoid the errors. For more information on the options just click the little "?" icon after SQL Options.
  8. If you want to save the backup as a file (recommended) then tick "Save as file" - Leave file name as is or edit for your needs. Select "gzipped" as compression. Now click "Go". If asked, choose "Save to disk" and save it wherever on your computer (it may take sometime depending on the size).
  9. If you want to show the whole backup SQL on your browser window, don't tick "Save as file" - once you have selected the tables you wish to backup (explained in step 5/6) click "Go". The page will now change and should show the SQL information (it may take sometime depending on the size). Copy and paste it to a text file or do whatever you want with it!
Note: Yes, the tables of the database will be shown to the far left in a frame, but they will also be displayed in a different form on this new page to the right in phpMyAdmin.

Congratulations! You have successfully backed up your database / selected tables!

Step 2 - Restoring your database using phpMyAdmin

Note: Most good hosts provide phpMyAdmin (mySQL Administration). If you do not know where it is or even if it exists on your server, just get in touch with your host.
  1. Login to phpMyAdmin.
  2. Select the database you wish to use.
  3. On the navigation bar on the top select "SQL" (besides Export, Structure, Search, Query... etc.)
  4. You should now be presented with a little page which allows you to run SQL query/queries on the database, either by inputting the query/queries to the input box or by locating a text file on your computer.
  5. You now have 2 options: 1) Paste the SQL which you backed up earlier in the "Input Box" and click "Go" or 2) If you saved the file on your PC then use the option below the first one; Click Browse > Locate the File > Click "Go". (Note: Most servers set a "Max File Size" for uploading the SQL, the size appears beside the Browse button.)
  6. It may take sometime for the file to be uploaded and fully run, so give it a chance. Once it worked, it will bring you back to the same page and should confirm if all went well "Your SQL-query has been executed successfully: The content of your file has been inserted."
Congratulations! If all went well, you have successfully restored your backed up database!

Step 3 - Backing up using SSH

Note: Some hosts do not offer SSH access, I suggest contacting your host and asking him/her if SSH access is enabled and if so the details. A good program to use for connecting via SSH is PuTTY (Get it at: http://www.chiark.greenend.org.uk/~sgtatham/putty/). Don't know how to use it? Search on Google for a tutorial.
  1. Connect to your host via SSH, login and run: mysqldump --opt -u user -p dbname > {path}/backup.sql
  2. You will be asked to type out your password once you run that command, do so and click enter. It may take some time for it to respond, but once completed you should be brought back to where you started (bash/command line).
Congratulations! You successfully backed up your database using SSH.

Step 4 - Restoring using SSH

Note: Some hosts do not offer SSH access, I suggest contacting your host and asking him/her if SSH access is enabled and if so the details. A good program to use for connecting via SSH is PuTTY (Get it at: http://www.chiark.greenend.org.uk/~sgtatham/putty/). Don't know how to use it? Search on Google for a tutorial.
  1. Connect to your host via SSH, login & run: mysql -u user -p dbname < {path}/backup.sql
  2. You will be asked to type out your password once you run that command, do so and click enter. It may take some time for it to respond, but once completed you should be brought back to where you started (bash/command line).
Congratulations! You have successfully restored your database using SSH.

That's basically it I think, I believe I have covered everything? Anything I missed? Comments or suggestions? Just let me know! Hope this tutorial was as useful to you as it is to me. :)

Thanks,
-Snake
www.metalgearforums.com

RFViet 02-03-2006 01:12 AM

My server just allows me to upload file size = 8Mb max. My sql file = 200 Mb. How do i restore ???

The Chief 02-03-2006 03:15 AM

Quote:

Originally Posted by RFViet
My server just allows me to upload file size = 8Mb max. My sql file = 200 Mb. How do i restore ???

You will have to use SSH, or ask your host to raise the max limit...

Snake 02-04-2006 11:17 AM

Or you can split every tables with the maximum of 8MB in each file... That's the best way to go for!

Rhoads 02-07-2006 08:48 AM

I tried but i get a error:

Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) when trying to connect -/bin/bash-2.05b$

Whats the problem, i use the command from your post, with my user and database name.

Snake 02-07-2006 01:37 PM

Hmm that's weird. I'm not sure about that error because it has nothing to do with my tutorial. And I bet you have done something wrong while attempting to restore your forums.

RFViet 02-08-2006 04:15 PM

Quote:

Originally Posted by Aftermath
Or you can split every tables with the maximum of 8MB in each file... That's the best way to go for!

Yeah , that's the way i want . How to do that ???

Logan70 02-10-2006 04:27 PM

You can also try and use:

http://www.ozerov.de/bigdump.php

It will allow for large dumps to be staggered, making it look like smaller pieces.

Ramsesx 02-12-2006 02:04 AM

I made it as described but my db file is only 1kb after downloading?

sinaluna 02-20-2006 05:07 PM

Should you close your board before backing up?

Thanks!

LincolnForums 02-20-2006 05:56 PM

Quote:

Originally Posted by Rhoads
I tried but i get a error:

Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) when trying to connect -/bin/bash-2.05b$

Whats the problem, i use the command from your post, with my user and database name.


This is due to a hosting problem, chances are good your host doesnt have something configured correctly. I had the same problem while using dreamhost

Quote:

Originally Posted by sinaluna
Should you close your board before backing up?

Thanks!


while its not neccassary, but you do run the chance of loosing any posts/changes that are made while backing up

Snake 03-28-2006 11:44 AM

Quote:

Originally Posted by sinaluna
Should you close your board before backing up?

Thanks!

Well I'd say yes just in case you won't loose any forum data (such as threads, posts, members, etc) while performing a backup. ;)

RFViet 03-29-2006 04:23 PM

Quote:

Originally Posted by Logan70
You can also try and use:

http://www.ozerov.de/bigdump.php

It will allow for large dumps to be staggered, making it look like smaller pieces.

thanks !!:cool:

imported_infitech 05-01-2006 11:00 PM

Now i coul dnot backup using SSH FROM the old server because the old server did not support SSH, but i backed up using your phpmyadmin method and through admincp just in-case.

My new host offers SSH so i want to restore using SSH. Is this possible?

Also to i type in
Code:

run: mysql -u joeuser -p mydatabase < {this/is/my/database/path}/thisthenameofthebackup.sql

Hornstar 05-03-2006 05:12 AM

this command mysqldump --opt -u user -p dbname > /path....

Does it compress the database?

As my old database size was 929 megs (done through cpanel) and this one is 721 megs. (done through SSH)

Bubble #5 05-06-2006 08:03 PM

Quote:

Originally Posted by Lil Ripsta
Select &quot;gzipped&quot; as compression.

Are you sure about that? vB suggests to not use any compression at all when saving the database...

Gunshot 05-07-2006 12:58 AM

Quote:

Originally Posted by hornstar1337
this command mysqldump --opt -u user -p dbname > /path....

Does it compress the database?

As my old database size was 929 megs (done through cpanel) and this one is 721 megs. (done through SSH)

I notice that the database size is smaller when backing up with ssh...

but having backed up and restored numerous times now using ssh and the command you have posted, I have found it to be very smooth and works perfectly. I was using myphpadmin for back ups and bigdump.php for restoring.......but as the database grew I began getting errors and this method became unusable...

not to mention I can backup and restore a database in about 10 minutes using ssh, while the other method can take hours. It really sucks to spend 3 plus hours only to find you have a corrupted db

TrueDeath 05-07-2006 11:36 AM

Some hosts also offer automated MySQL backups at your defined times/when you select, you could always use https://vborg.vbsupport.ru/showthread.php?t=103259 if your worried about lost data.

Bubble #5 05-07-2006 03:44 PM

Quote:

Originally Posted by TrueDeath
Some hosts also offer automated MySQL backups at your defined times/when you select

Site5 has a unique feature called 'Flashback' which automatically backs up every file that is one the server. You don't have to do anything. To restore a file simply click it from a master list and it's restored :bunny:

Snake 05-07-2006 05:50 PM

Whoa that's pretty hot. Is that a feature-already in cPanel 'cause I am always hoping for an automatic backup system for cPanel.

Bubble #5 05-07-2006 06:53 PM

Quote:

Originally Posted by Lil Ripsta
Whoa that's pretty hot. Is that a feature-already in cPanel 'cause I am always hoping for an automatic backup system for cPanel.

They don't use cPanel, they use their own scripts (called netadmin) and I must say it's the nicest (and easiest to use) control panel that we've ever seen :banana:

furst 06-02-2006 02:55 AM

I'm trying to move from one server to another. The server I am moving FROM doesn't have ssh access so I'll have to do it in phpmyadmin. The server I'm moving TO does not have phpmyadmin so I'll have to use the ssh method.

Can I use part 1 of the phpmyadmin tutorial and part 2 of the ssh tutorial? It's okay to combine the two like that, isn't it?

Chevy II 06-03-2006 03:02 AM

Hi,
I'm restoring my database using phpMyAdmin and I followed step 2 in the first post when attempting to restored the db. When I do this I get the following error, does anyone know why or how to fix this?

Quote:

SQL query:

_sitedb_.sql

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_sitedb_.sql' at line 1

SixteenOhNine 06-04-2006 04:55 AM

Using SSH to backup your SQL file doens't specifically compress the database, the --opt command optimizes the database and clears the overhead on each table. While it may appear to be smaller, the database is actually the same size, without the overhead.

As for Site5, they actually do use CPanel, it is simply a skinned version of CPanel which is rebranded. They have indeed added their own features, such as FlashBack and such services, however it's easy to see they still use a rebranded version of CPanel :).

G_Man 06-26-2006 04:30 AM

Quote:

Originally Posted by Bubble #5
Site5 has a unique feature called 'Flashback' which automatically backs up every file that is one the server. You don't have to do anything. To restore a file simply click it from a master list and it's restored :bunny:

Site5 still recommends you use phpAdmin to backup your databases though.....


Which brings me to my question for anyone who can help -

When phpAdmin asks for a filename template for the database backup file there is this message below:

Quote:

This value is interpreted using strftime, so you can use time formatting strings. Additionally the following transformations will happen: __SERVER__/server name, __DB__/database name. Other text will be kept as is.

Okay, I assume this means I can put something in the template which cause the filename to include the date/time, but I don't know what. Anyone help me with this??

Cheers. :D

Bubble #5 06-26-2006 05:35 AM

Quote:

Originally Posted by G_Man
Site5 still recommends you use phpAdmin to backup your databases though.....

That's because Flashback doesn't back up databases yet ;)

frandy 07-20-2006 07:23 PM

how do you find the correct path??

webgeek247 09-09-2006 11:45 AM

My previous host had ssh access, my new host doesnt, so I used the bigdump method, which seemed to have restored the mysql file on my new database, now I cant view my forums homepage (its blank) however I can log into admin cp without a problem :confused: :confused:

CBrown 09-09-2006 07:38 PM

I'm having some issues myself...

I'm all backed up via the export function on my old server. Fine.
I have a new dedicated server. So I created the database, and user for sql.

Problems.

I don't think I'm setting up the permissions for that new user correctly... I'm using plesk to add the new database and user. Fine.

I try to restore the database via ssh, and I get:

Can't create database 'DB_Name'; database exists

Ugh... So what is the issue there? If I delete the database, and do it that way, I get the errors saying no database exists. So I feel like i'm stuck.

I know there is probably a simple answer, but I just cant find it.


Thanks in advance folks.


Carter

Ah ha.. think I found the answer...

in ssh.. on a new server... use the "-f" command to ignore the error messages.
That fixed it.

sql -f -u USERNAME -p DB_NAME < /Path_to/sql_dump_file.sql

@dj

look here:
http://www.vbulletin.com/docs/html/blank_pages

webgeek247 09-10-2006 07:55 AM

Quote:

Originally Posted by CBrown

Thanks for that CBrown, it got the homepage displaying however I'm getting the following error now on the top of my forums homepage :hurt:

Quote:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /websites/LinuxPackage02/xx/xx/xx/xxxxxx/public_html/forums/index.php(485) : eval()'d code on line 18

mojo8850 10-06-2006 03:46 PM

I am getting an error Access Denied For User ****

Help Me Only Small Database.

Snake 10-06-2006 08:53 PM

Were you trying to restore the database through phpMyAdmin or via SSH?

Aclikyano 11-09-2006 03:59 PM

OK, I have a problem..What if you dont know the exact path of the db.sql file what would be the best way to find this out through ssh

Snake 01-04-2007 10:10 PM

Uhh I'm not really familiar with SSH but why don't you just use phpMyAdmin or the mySQL dumb tool?

taumau 02-10-2007 12:31 PM

Which way is more safe?

Through phpMyAdmin or SSH? :confused:

Thank you :)

Snake 02-11-2007 02:02 PM

To be honest with you, I have to say that SSH is much safer and probably easier to use than phpMyAdmin. You might have access to shell on your server so you might wanna contact your host first and gain more information regarding this.

taumau 02-14-2007 11:15 PM

I followed all the steps and in the end I downloaded a file with 13,5Mb.

But my forum has 5800 topics and more than 150.000 posts.

Can this be right? :confused:


PS- I backup through phpMyAdmin. I don?t have SSH access

Snake 02-16-2007 02:42 PM

Well, if you haven't got any major mods and stuff like that installed on your forum then yeah, how it cannot be right? ;)

Delphiprogrammi 02-27-2007 02:16 PM

hi,
I don't get the "hassle" people make about this.Just login to SSH and type

Quote:

mysqldump --opt -Q -u mysql_username -p mysql_databasename > file.sql
enter password:Mysql_databasepassword
done as easy as that

Shazz 02-27-2007 02:23 PM

Some hosts/sites don't have access to SSH?
Interesting...

I use SSH, Its very easy,quick and nice


All times are GMT. The time now is 11:37 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01444 seconds
  • Memory Usage 1,841KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (17)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete