IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » backup The latest public backup snipts.

showing 1-20 of 27 snipts for backup
  • How to Dump All Databases in MySQL Server
    mysqldump -u username -ppassword –all-databases > dump.sql
    

    copy | embed

    0 comments - tagged in  posted by Navetz on Aug 31, 2010 at 10:35 p.m. EDT
  • Multiple DB backup
    DECLARE @name VARCHAR(50) -- database name  
    DECLARE @path VARCHAR(256) -- path for backup files  
    DECLARE @fileName VARCHAR(256) -- filename for backup  
    DECLARE @fileDate VARCHAR(20) -- used for file name 
    
    SET @path = 'C:\Backup\'  
    
    SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) 
    
    DECLARE db_cursor CURSOR FOR  
    SELECT name 
    FROM master.dbo.sysdatabases 
    WHERE name NOT IN ('master','model','msdb','tempdb')  
    
    OPEN db_cursor   
    FETCH NEXT FROM db_cursor INTO @name   
    
    WHILE @@FETCH_STATUS = 0   
    BEGIN   
           SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
           BACKUP DATABASE @name TO DISK = @fileName  
    
           FETCH NEXT FROM db_cursor INTO @name   
    END   
    
    CLOSE db_cursor   
    DEALLOCATE db_cursor
    

    copy | embed

    0 comments - tagged in  posted by aturgarg on Jul 12, 2010 at 7:02 a.m. EDT
  • HOW TO: FIX A BROKEN PLESK BACKUP
    #To fix a broken Plesk backup, you follow these steps to fix the stuck process. This must #be done from SSH logged in as root.
    
    #The first thing to try is to look for any running backups that may be hung:
    
    mysql -u admin -p`cat /etc/psa/.psa.shadow`
    mysql>use psa;
    mysql>select * from BackupsRunning;
    
    #If there are any entries in here, they can be removed.  Dates older than at least three #days are a good sign a backup process is hung and causing the error. To remove currently #running backups:
    
    mysql>delete from BackupsRunning; 
    
    #Another option is to clear the backup jobs from the plesk database.  This will remove all #scheduled backups and the client will need to re-create their backup jobs. 
    
    mysql -uadmin -p`cat /etc/psa/.psa.shadow`
    mysql> use psa;
    mysql>select * from BackupsSettings;
    mysql> delete from BackupsSettings;
    
    #This will remove all the backup settings and will have the initial backup configuration - an empty set. These steps should clear any errors with the plesk backups.
    

    copy | embed

    0 comments - tagged in  posted by toberlander on Jun 08, 2010 at 3:01 p.m. EDT
  • (gs) Grid-Service backup to Amazon S3
    Automated Backup for (gs) Grid-Service to Amazon S3
    http://www.christinawarren.com/2008/06/24/s3-backup-media-temple-gs/
    
    http://code.google.com/p/ziplinebackup/
    

    copy | embed

    0 comments - tagged in  posted by abecker on May 13, 2010 at 7:36 p.m. EDT
  • Database dump and import from the commandline
    #dump
    mysqldump db_name --user=db_user -p > backup.sql
    
    #import
    mysql --user=username -p db_name < backup.sql
    

    copy | embed

    0 comments - tagged in  posted by torkil on Mar 17, 2010 at 10:51 a.m. EDT
  • backup all git repositories that are in one folder
    #!/bin/bash
    
    BACKUP_FOLDER="/home/srvadm/p2backups"
    NUM_GROUPS="30"
    
    cd "$BACKUP_FOLDER"
    
    echo "backup at: `date`"
    
    for i in `ls`; do
    	if [ -d "$i" ]; then
    		echo "backing up repository: $i"
    		cd "$i"
    		git pull
    		cd ..
    	fi
    done
    

    copy | embed

    0 comments - tagged in  posted by prauber on Feb 25, 2010 at 5:55 a.m. EST
  • backup DB with PHP script+Ajax
    <?php 
    // in adminDBSuccess.php template file, call another action "ajaxBackup" with Ajax
    echo jq_link_to_remote(image_tag('backup'),
        array
        (
          'update' =>'feedback_backup',
          'url'    =>'homepage/ajaxBackup',
          'loading' => jq_visual_effect('fadeIn',  '#indicator_backup'),
          'complete'=> jq_visual_effect('fadeOut', '#indicator_backup')
        ));
    ?>
    
    // action ajaxBackup in actions.class.php
    public function executeAjaxBackup(sfWebRequest $request)
    {
      return $this->renderPartial('homepage/backupDBSuccess');
    }
    
    //_backupDBSuccess.php partial template
    <?php if(!require_once(dirname(__FILE__).'/../../../../../web/backup.php')): ?>
      <?php echo "backup.php file not found or it doesn't work correctly." ?>
    <?php endif; ?>
    
    // backup.php script to backup DB
    <?php
    include('db_config.php');
    
    backup_tables($dbhost,$dbuser,$dbpassword,$dbname,$tables, $backup_dir);
    
    /* backup the db OR just a table */
    function backup_tables($host,$user,$pass,$name,$tables, $backup_dir)
    {
    	$return ='';
    	$link = mysql_connect($host,$user,$pass);
    	mysql_select_db($name,$link);
    	
    	//get all of the tables
    	if($tables == '*')
    	{
    		$tables = array();
    		$result = mysql_query('SHOW TABLES');
    		while($row = mysql_fetch_row($result))
    		{
    			$tables[] = $row[0];
    		}
    	}
    	else
    	{
    		$tables = is_array($tables) ? $tables : explode(',',$tables);
    	}
    	
    	//cycle through
    	$return.='SET FOREIGN_KEY_CHECKS=0;'."\n";
    	foreach($tables as $table)
    	{
    		$result = mysql_query('SELECT * FROM '.$table);
    		$num_fields = mysql_num_fields($result);
    		
    		$return.= 'DROP TABLE '.$table.';';
    		$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    		$return.= "\n\n".$row2[1].";\n\n";
    		
    		for ($i = 0; $i < $num_fields; $i++) 
    		{
    			while($row = mysql_fetch_row($result))
    			{
    				$return.= 'INSERT INTO '.$table.' VALUES(';
    				for($j=0; $j<$num_fields; $j++) 
    				{
    					$row[$j] = addslashes($row[$j]);
    					$row[$j] = ereg_replace("\n","\\n",$row[$j]);
    					if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
    					if ($j<($num_fields-1)) { $return.= ','; }
    				}
    				$return.= ");\n";
    			}
    		}
    		$return.="\n\n\n";
    	}
    	$return.='SET FOREIGN_KEY_CHECKS=1;'." \n";
    	
    	//save file
            
    	//$handle = fopen($backup_dir.'db-backup-'.date('Y-m-d').'-'.(md5(implode(',',$tables))).'.sql','w+');
    	$filename = date('Y-m-d_H:i:s').'.sql';
    	$handle = fopen($backup_dir.$filename,'w+');
    	fwrite($handle,$return);
    	echo sprintf('[%s] DB backup successed !<br> <small>%s</small><br>',date('Y-m-d H:i:s'),$backup_dir.$filename);
    	fclose($handle);
    }//end function
    
    // DB configuration file db_config.php
    <?php
    
    
    // please configurate here your db connection and path of backup
    $dbhost = "localhost";
    
    $dbname = "kqb";
    
    $dbuser = "root";
    
    $dbpassword = "something";
    
    $tables ='*'; //if only one table should be saved, give the name of table. Default *, means any table in DB
    
    $backup_dir ='/var/www/clean/kqb-v2/backup/'; // Folder where sql should be stored, please "chmodd 777 $backup_dir"
    

    copy | embed

    0 comments - tagged in  posted by toledot on Feb 23, 2010 at 7:30 a.m. EST
  • Archive mail with archivemail into mbox format
    archivemail --date=2010-01-15 --dont-mangle --include-flagged -n -v --output-dir=archived imaps://"user@domain.com":"password"@mail.domain.com/INBOX.Sent
    

    copy | embed

    0 comments - tagged in  posted by malkir on Jan 27, 2010 at 11:53 p.m. EST
  • Insert SQL via command line
    -- insert sql via command line
    mysql -u dbuser -p -h dbhost.yoursite.com dbname < /path/to/backup.sql
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Dec 07, 2009 at 1:59 p.m. EST
  • backup a database using date as name file
    mysqldump -u <user> -p<pass> <mysite> -r <mysite>-$(date +%d.%b.%Y).sql
    

    copy | embed

    0 comments - tagged in  posted by juque on Nov 06, 2009 at 6:52 p.m. EST
  • burn cd and dvd's in ubuntu
    #make the image
    $ mkisofs -r -J -o yourbackup.iso /home/path_to/your_files
    #record the image
    $ cdrecord -v dev=/dev/cdrw --speed=24 -data dfdsdf-02Nov.iso
    
    #make an image from a video dvd
    $ cat /dev/scd0 > ./orange_county_fl_video.iso
    #burn the video dvd
    $ growisofs -dvd-compat -speed=12 -Z /dev/dvdrw=orange_county_fl_video.iso 
    
    #burn dvd
    $ growisofs -dvd-compat -speed=12 -Z /dev/dvdrw -joliet-long -R -V "myVolume" <filename>
    # dual layer like above
    growisofs -dvd-compat -speed=12 -Z /dev/dvdrw1 -joliet-long -allow-limited-size -R -V "myVolume" <filename>
    
    $ growisofs -Z /dev/dvdrw -R -J /some/files
    #can also use cdrecord to burn dvds
    $ cdrecord -v dev=/dev/cdrw --speed=24 -data dfdsdf-02Nov.iso
    

    copy | embed

    0 comments - tagged in  posted by tayhimself on Nov 03, 2009 at 6:41 p.m. EST
  • backup databases from a list of i
    mysql -u admin -p`cat /etc/psa/.psa.shadow` psa -e 'SELECT data_bases.name AS "database" FROM data_bases;' > dbnames | sed 's/database//g' dbnames > dbnames2 && cat dbnames2
    
    for i in `cat dbnames2`; do mysqldump --add-drop-table -u admin -p$(cat /etc/psa/.psa.shadow) $i > ${i}-`date +"%m-%d-%y"`.sql; done
    

    copy | embed

    0 comments - tagged in  posted by malkir on Oct 29, 2009 at 6:34 p.m. EDT
  • Moving Magento to another server (the backup part)
    #!/bin/bash
    
    clear
    stty erase '^?'
    
    echo "-- File and DB Backup of Magento --"
    echo "The moving an installation of Magento as written on http://www.magentocommerce.com/wiki/groups/227/moving_magento_to_another_server"
    echo "Please note: It does not backup all the extensions and additional plugins. Back up all the files you added or changed manualy."
    echo
    
    check_dest_dir () {
        echo -n "Please enter the name of the directory the backup files will be stored in: "
        read dest_dir 
        
        if [ -d "$dest_dir" ]; then
        	  echo -n "Directory already exists. Use it for Backup [y] or specify another one [n]?"
        	  read use_dest_dir;
            if  [ "$use_dest_dir" = "y" ] ; then
               do_backup $dest_dir; 
               else  check_dest_dir;
            fi
        
        else 
            echo -n "Directory does not exist. Create it [c] or specify another one [n]?"
            read use_dest_dir
            if  [ "$use_dest_dir" = "c" ] ; then
               echo "Directory /"$dest_dir/" is to be created..."
               mkdir $dest_dir;
               do_backup $dest_dir;
            else check_dest_dir;
            fi
        fi
    }
    
    do_backup(){
        clear
        echo -n "Do the DATABASE dump? [y/n]"
        read do_database_dump
        if [ "$do_database_dump" = "y" ] ; then
          echo "Please enter the required information:"
          echo  -n  "- Database Host (usually localhost): "
          read  dbhost
          echo  -n  "- Database Name: "
          read  dbname
          echo  -n  "- Database User: "
          read  dbuser
          echo  -n  "- Database Password: "
          read  dbpass 
          echo "Creationg database DUMP. Please wait..."
          mysqldump -h DBHOST -u DBUSER -pDBPASS DBNAME > data.sql
          echo "Moving data.sql to your backup directory ($1)"
          mv data.sql $1/
        fi
         
       clear
       echo "TARing MEDIA..."
       tar -cvf media.tar media/*
       echo "Moving media.tar to your backup directory ($1)"
       mv media.tar $1/
      
       clear
       cd app/design/frontend/default/
       echo -n "About to TAR your Theme. What's the name of it?"
       read mytheme
       if [ -d "$mytheme" ]; then
          echo "Specified Theme Directory exists. TARing from app/ ..."
          tar -cvf app.tar $mytheme/
          echo "Moving app.tar to your backup directory ($1)"
          mv app.tar ../../../../$1/
          echo "TARing from skin/..."      
          cd ../../../../skin/frontend/default/
          tar -cvf skin.tar $mytheme/
          echo "Moving skin.tar to your backup directory ($1)"
          mv skin.tar ../../../$1/
       fi
       clear
       echo "Copying local.xml to your backup directory ($1)"
       cd ../../../
       cp app/etc/local.xml $1/
       echo "Copying .htaccess and php.ini to your backup directory ($1)"
       cp .htaccess php.ini $1/
       clear
       cd $1
       echo "Files in your backup:"
       ls     
    }
    
    check_dest_dir;
    

    copy | embed

    1 comment - tagged in  posted by lecomm on Oct 16, 2009 at 7:44 p.m. EDT
  • time machine interval
    $sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 14400
    

    copy | embed

    0 comments - tagged in  posted by tayhimself on Sep 17, 2009 at 11:41 a.m. EDT
  • make backup of all my github repos
    #!/bin/bash
    for NAME in backup.pl bmconverter.py convert_encoding.py \
    decay fortune.py git-graph gmail_archive.py liberator \
    mail.pl pdfWriteBookmarks pidgin2adiumlog procimap pyala \
    stoptimer texmf texpreview vimrc; do
        rm -rf $NAME.git
        git clone --bare git://github.com/goerz/$NAME.git $NAME.git
        (cd $NAME.git \
            && git remote add --mirror origin git://github.com/goerz/$NAME.git)
    done
    

    copy | embed

    0 comments - tagged in  posted by goerz on Aug 18, 2009 at 4:17 p.m. EDT
  • Locally backup remote files via ssh
    ssh remote-login@192.168.1.10 "cd /; tar -cvf - / | gzip -c" > backup.tar.gz
    

    copy | embed

    0 comments - tagged in  posted by fraktil on Aug 08, 2009 at 6:55 p.m. EDT
  • Restore and Import MySQL dump
    mysql -u username -ppassword database_name < dump.sql
    

    copy | embed

    0 comments - tagged in  posted by njoubert on Jul 15, 2009 at 3:27 a.m. EDT
  • Backup ALL MySQL DBs
    mysqldump -u username -ppassword –all-databases > dump.sql
    

    copy | embed

    0 comments - tagged in  posted by njoubert on Jul 15, 2009 at 3:26 a.m. EDT
  • Backup and compress a MySQL DB
    mysqldump $DB_NAME -R -q --user=$USER --password=$PASSWORD --lock-tables | gzip > $BACKUPDIR/$BACKUPNAME
    

    copy | embed

    0 comments - tagged in  posted by njoubert on Jul 14, 2009 at 8:59 p.m. EDT
  • backup production to local machine (supports multistage)
    # adapted from http://blog.caboo.se/articles/2006/12/28/a-better-capistrano-backup
    # supports multistage deploy setup
    # allows for restore and local database imports
    
    namespace :db do
      desc "Copy the remote production database to the local development machine" 
      task :backup, :roles => :db, :only => { :primary => true } do
        get("#{shared_path}/config/database.yml", "tmp/#{stage}-database.yml")
        
        filename = "#{application}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.sql.bz2" 
        backupfile = "#{shared_path}/tmp/#{filename}" 
        
        config = YAML::load_file("tmp/#{stage}-database.yml")["#{rails_env}"]
        
        on_rollback { run "rm #{filename}" }
        run "mysqldump -u'#{config["username"]}' -p'#{config["password"]}' -h'#{config["host"]}' '#{config["database"]}'  | bzip2 -c > #{backupfile}"
        
        `mkdir -p #{File.dirname(__FILE__)}/../backups/#{stage.to_s}`
        get backupfile, "backups/#{stage.to_s}/#{filename}" 
        
        run "rm #{backupfile}" 
        run_locally("rm tmp/#{stage}-database.yml")
      end
      
      desc "Restore the local backup to the production database"
      task :restore_backup, :roles => :db, :only => { :primary => true } do
        backupfile = `ls -tr backups/#{stage.to_s} | tail -n 1`.chomp
        restorefile = "/tmp/restore_#{application}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.sql"
        if backupfile.empty?
          logger.important "No backups found" 
        else
          logger.debug "Loading #{backupfile} into remote database on #{stage.to_s.upcase}"
          upload("backups/#{stage.to_s}/#{backupfile}", "#{restorefile}.bz2")
          database_yml = ""
          data = capture "cat #{shared_path}/config/database.yml"
          config = YAML::load(data)['production']
          mysql_import = "bzip2 -d #{restorefile}.bz2 && mysql -u #{config['username']} -p'#{config['password']}' -h #{config['host']} #{config['database']} < #{restorefile}"
          # surpress debug log output to hide the password
          current_logger_level = self.logger.level
          logger.debug %(executing "#{mysql_import.sub(/-p\S+/, '-p')}")
          self.logger.level = Capistrano::Logger::INFO
          run mysql_import do |channel, stream, data|
            puts data 
          end
          # restore logger level
          self.logger.level = current_logger_level
          run "rm #{restorefile}" 
          logger.debug "command finished" 
        end
      end
    
      desc "Import the latest backup to the local development database" 
      task :import_backup do
        backupfile = `ls -tr backups/#{stage.to_s} | tail -n 1`.chomp
        if backupfile.empty?
          logger.important "No backups found" 
        else
          config = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'database.yml'))).result)['development']
          logger.debug "Loading backups/#{stage.to_s}/#{backupfile} into local development database" 
          `bzip2 -cd backups/#{stage.to_s}/#{backupfile} | mysql -u #{config['username']} --password=#{config['password']} #{config['database']}`
          logger.debug "command finished" 
        end
      end
    
      desc "Backup the remote production database and import it to the local development database" 
      task :backup_and_import do
        backup
        import_backup
      end
    end
    
    ## NOTE: remove #{stage.to_s} from filename 
    ## if you don't have multistage deploy env
    

    copy | embed

    0 comments - tagged in  posted by melzz on Jun 26, 2009 at 8:56 p.m. EDT
Sign up to create your own snipts, or login.