Activity Stream
48,167 MEMBERS
62912 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 9 of 9
  1.     
    #1
    Member

    Lightbulb How to: remotely backup your DB (bash script)

    hello mateys,
    i've put up some basic shell commands (with the help of our beloved lord google the mighty) that will allow you to backup your DBs locally, gzipped it and then send it thru ftp to safe place you've picked

    Code: 
    #!/bin/bash
    mysqldump -uYOURUSERNAME -pYOURPASS -hlocalhost YOURDBNAME > /your/path/backup-`date +%d%m%y`.sql
    tar -zcvf /your/path/zippedbackup-`date +%d%m%y`.tgz /your/path/*.sql
    
    cd /your/path
    HOST='YOURFTPHOST'
    USER='YOURFTPUSERNAME'
    PASSWD='YOURFTPPASS'
    ftp -n -v $HOST << EOT
    binary
    user $USER $PASSWD
    prompt
    put zippedbackup-*
    bye
    EOT
    
    rm -rf /your/path/*
    
    exit 0
    that's it. you can run it automatically using cron or nohup.
    also don't forget to chmod it first to 755 so that the script can be executed

    hope that helps.
    masterbator Reviewed by masterbator on . How to: remotely backup your DB (bash script) hello mateys, i've put up some basic shell commands (with the help of our beloved lord google the mighty) that will allow you to backup your DBs locally, gzipped it and then send it thru ftp to safe place you've picked #!/bin/bash mysqldump -uYOURUSERNAME -pYOURPASS -hlocalhost YOURDBNAME > /your/path/backup-`date +%d%m%y`.sql tar -zcvf /your/path/zippedbackup-`date +%d%m%y`.tgz /your/path/*.sql cd /your/path HOST='YOURFTPHOST' Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Be very carefull what you put here, I would even remove that line.

    PHP Code: 
    rm -rf /your/path/* 

  4.     
    #3
    Member
    Quote Originally Posted by Gavo View Post
    Be very carefull what you put here, I would even remove that line.

    PHP Code: 
    rm -rf /your/path/* 
    well i put that command there intentionally, that's just temporary folder, so once the ftp transfer has been completed, the local backup folder (which was /your/path/) is empty and ready to be filled again with newest backup files

  5.     
    #4
    Member
    Website's:
    freshimg.com
    ftp command not found error

  6.     
    #5
    Member
    Quote Originally Posted by yuvraj View Post
    ftp command not found error
    you need to install ftp on your server

  7.     
    #6
    Member
    Website's:
    freshimg.com
    : command not found:
    : command not found:
    : command not found1:
    : command not found4:
    : Name or service not known
    Not connected.
    Not connected.
    Not connected.
    ?Invalid command
    : command not found2:
    : numeric argument required 0
    i am able to login in ftp account
    so it mean ftp is installed and working
    remote ftp account with putty

  8.     
    #7
    Member
    try login on ssh
    then type ftp

  9.     
    #8
    Member
    @Masterbator, I don't need the FTP, I will manually download it everyday, but I just need the script to zip the site folders and mysql into one location. Did I modify your script correctly? And this is for Centos 5-6?

    I'm using fake user/pass and locations, so no worries.
    Code: 
    #!/bin/bash
    mysqldump -uLudo8 -pludo8 -hlocalhost ludodb > /var/www/mysite-`date +%d%m%y`.sql
    tar -zcvf /var/www/mysite/backups-`date +%d%m%y`.tgz /var/www/mysite/backups*.sql
    
    
    
    exit 0
    Also is it -uLudo8 or -u Ludo8?

  10.     
    #9
    Member
    Quote Originally Posted by LuDo8 View Post
    @Masterbator, I don't need the FTP, I will manually download it everyday, but I just need the script to zip the site folders and mysql into one location. Did I modify your script correctly? And this is for Centos 5-6?

    I'm using fake user/pass and locations, so no worries.
    Code: 
    #!/bin/bash
    mysqldump -uLudo8 -pludo8 -hlocalhost ludodb > /var/www/mysite-`date +%d%m%y`.sql
    tar -zcvf /var/www/mysite/backups-`date +%d%m%y`.tgz /var/www/mysite/backups*.sql
    
    
    
    exit 0
    this works for any linux distro mate

    i think this script will work for your purpose:
    Code: 
    #!/bin/bash
    mysqldump -uLudo8 -pludo8 -hlocalhost ludodb > /var/www/yoursite/DB-`date +%d-%m-%y`.sql
    tar -zcf /var/www/backupfolder/yoursitefull-`date +%d-%m-%y`.tgz /var/www/yoursite/*
    
    
    
    exit 0
    then you just have to go to /var/www/backupfolder/
    and download your full backup (DB+site) from there (the yoursitefull.tgz file)

    Quote Originally Posted by LuDo8 View Post
    Also is it -uLudo8 or -u Ludo8?
    doesn't matter, it will work with or without a space

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. bash script mass download from links in text file
    By Mutikasa in forum Tutorials and Guides
    Replies: 1
    Last Post: 9th May 2012, 04:20 PM
  2. OpenVPN For VZ VPS Bash Script. "CentOS"
    By dotvps in forum Tutorials and Guides
    Replies: 4
    Last Post: 28th Feb 2012, 01:07 PM
  3. mass upload bash script (good for Megaupload)
    By Mutikasa in forum Tutorials and Guides
    Replies: 7
    Last Post: 13th Jan 2012, 12:54 PM
  4. ssh/bash script
    By t3od0r in forum Technical Help Desk Support
    Replies: 0
    Last Post: 6th Oct 2010, 06:41 PM
  5. Need A Bash Script
    By orbofdarkness in forum Technical Help Desk Support
    Replies: 14
    Last Post: 8th Feb 2010, 08:02 PM

Tags for this Thread

BE SOCIAL