Simple Linux Backup with SCP and TAR

I ran into a problem this week when I tried to pull a file off of a backup and found out that I could not read any of the backup tapes that I had. I was using Dump to create the backups and when I tried to access them with Restore I got the error message that the tape was not a dump tape. I had tested this before I put the server into place, but something has changed in the last two months. I decided to change to a different method of creating backups. I am now going to tar the server and then use scp to move the tar file to a second server that is located off site.

Lets start with setting the machines up so that we can transfer files between the two servers without being prompted for a password. For this posting server1 will be the server that is being backed up and server2 will be the server that we are sending the backup to.

Configure the Client (server1)
Create the client key without a password:
[root@server1 /]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key [/root/.ssh/id_dsa]:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa
Your public key has been saved in /root/.ssh/id_dsa.pub
The key fingerprint is 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:root@server1

Lets take a look at the key:
[root@server1 /]# cd ~/.shh
[root@server1 /]# ls
id_dsa id_dsa.pub known_hosts

Copy the key to the server that we are going to copy the backup to:
[root@server1 /]# scp -r id_dsa.pub root@server1:key-temp.pub

Configure the server (server2)
Lets make a .ssh directory if the directory does not exist:
[root@server2:~#] mkdir .ssh
[root@server2:~#] chmod 700 .ssh
[root@server2:~#] cd .ssh

Add the key for the client to the authorized keys:
[root@server2:~#] cat ~/key-temp.pub >> authorized_keys
[root@server2:~#] rm ~/key-temp.pub

You should now be able to use ssh and scp from serve1 to server2 without being prompted for a password.

From here I had to create the script for creating the tar file of server1 and then copying it to server2. I created a directory called backup to hold my script and the MySQL backups. So on server1 we are going to create the directory and the script:
[root@server1: /#] cd /
[root@server1: /#] mkdir /backup
[root@server1: /#] cd /backup
[root@server1: /#] nano backup.sh

Now the script:
#!/bin/sh

# Define the variables for later use:
BACKUPFILE=backup-$(date +%Y%m%d)
OLDFILE=backup-$(date --date='7 day ago' +%Y%m%d) # We are keeping 7 days of databases dumps.
EXCLUDES="--exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/media --exclude=$BACKUPFILE.tgz"
BACKUPDIR=/
COPYTO=root@server2:/root/.


# Backup the MySQL Databases:
mysqldump -uroot --opt databasename1 > /backup/databasename1-$BACKUPFILE.sql
mysqldump -uroot --opt databasename2 > /backup/databasename2-$BACKUPFILE.sql


# Create the tar file:
tar cvpzf $BACKUPFILE.tgz $EXCLUDES $BACKUPDIR


# Upload the tar file:
scp -rp $BACKUPFILE.tgz $COPYTO


# Remove the backup file:
rm $BACKUPFILE.tgz
rm /backup/databasename1-$OLDFILE.sql
rm /backup/databasename2-$OLDFILE.sql

You should now be able to backup server1 with the command:
[root@server1: /#] sh /backup/backup.sh

Just want to say thanks to David for his demo at the last ECLUG meeting, because it gave me the point to jump off at.

ECLUG Meeting for December

David Desrosiers did a pair of presentations for this months meeting. His first presentation was a short demonstration on Bash hacks and tips. Some of the things that can be done with Bash are:

  • Integer math
  • Scripting, functions, loops
    • Download sequential files remotely
    • Rename local files sequentially
    • Repeat a process ‘n’ times until completed

  • Regular expressions
    • Character classes
      • [:alnum:], [:alpha:], [:blank:], [:digit:], [:lower:] and so on.

    • Globbing

  • I/O redirection
  • vi! (no, seriously)
  • Subshells and restricted shells
  • Aliases and variables

The second presentation was about Firefox and its extensions. So what makes Firefox different?

  • Support for enhanced “Tabbed Browsing”
    • Makes surfing the web faster

  • Advanced Privacy and Annoyance features
    • Pop-up blocking
    • Form and password management
    • Cookie preferences/expiration

  • Faster searching, find things easier
  • Better Bookmarks and History support
  • Does not directly support ActiveX
  • Customizable and extendable, thousands of extensions and themes available
  • Smart Download Manager
  • Standards compliant
  • Faster than other browsers out there
  • Fully Open Source

Why not just use Internet Explorer?

  • Slow, implements many hacks and workarounds to achieve speed, breaks RFC standards
  • Insecure, source of many hijacked Windows machines (thousands of open security issues)
  • No updates in 4+ years (MSIE 7.x has recently been released in betas, not available for all Windows versions as yet), “long in the tooth”
  • No support for PNG images
  • Not standards-compliant, renders HTML horribly, no support for XHTML or CSS2/CSS3

What are “Extensions” and how do I get them?

  • Used to add features not in the core browser. Find something lacking? Add an extension!
  • Used to replace features that you may not like. Changes how you interact with the browser
  • Change the way the browser “looks & feels” to make it easier for you to use it
  • Tools -> Extensions -> Get More Extensions
  • Point your browser to https://addons.mozilla.org/

What extensions are available?

  • Blogging
  • Bookmarks
  • Contacts
  • Developer Tools
    • Greasemonkey – http://www.diveintogreasemonkey.org/
      • Allows you to write scripts that alter the web pages you visit, thousands of “user scripts” to start with

    • Timestamp Converter
      • Context menu option to convert the selected timestamp into a date.

    • Total Validator
      • Perform multiple validations and take screen shots in one go rather than using separate tools.

    • Prefbar
      • Gives the user more control over the pages viewed

    • Tamper Data
      • Use tamperdata to view and modify HTTP/HTTPS headers and post parameters.

    • Web Developer
      • Adds a menu and a toolbar with various web developer tools.

    • RankQuest SEO Toolbar
      • Quick access to more than 30 intuitive SEO tools

    • Google PageRank Status
      • Display the google pagerank in your browser’s status bar.

    • SearchStatus
      • Allows you to see how any and every website is performing (for SEM/SEOs)

    • Live HTTP Headers
      • Detailed information about HTTP request/response headers

    • FireBug
      • All of the tools you need to poke, prod, and monitor your JavaScript, CSS, HTML and Ajax are brought together

    • Leak Monitor
      • Pops up an alert dialog to warn chrome and extension developers about one particular type of leak (errant Javascript objects).

  • Dictionaries
  • Download Tools
    • Torrent Search
      • Search for torrents on the top 29 top torrent search engines

    • FlashGot
      • Download just one link, selected links or all the links of a page together at maximum speed with a single click

    • Linky
      • Open/download/validate links and pictures in tabs or windows.

    • DownThemAll
      • Lets you download all the links or images contained in a webpage directly or via advanced filters

    • Gmail Space
      • This extension allows you to use your Gmail Space (2 GB) for file storage. It acts as a remote machine.

  • Editing and Forms
  • Entertainment
  • Humor
  • Image Browsing
  • Kiosk Browsing
  • Languages
  • Message Reading
  • Miscellaneous
  • Navigation
  • News Reading
  • Privacy and Security
    • Adblock Plus/Adblock Filterset.G
      • Block annoying banner ads and other distracting page elements in a few clicks and automated updates of the latest filter lists

    • SwitchProxy Tool
      • lets you manage and switch between multiple proxy configurations quickly and easily, also acts as an anonymizer

    • CustomizeGoogle
      • Enhance Google search results by adding extra information (like links to Yahoo, Ask.com, MSN etc) and removing unwanted information (like ads and spam).

    • NoScript
      • NoScript allows JavaScript, Java and other executable content only for trusted domains of your choice, e.g. your home-banking web site.

    • DiggiDig
      • Adds a menu button next to the address bar with actions relevant to the current URL, for example to step out to the parent directory, or to visit the equivalent ftp URL, or to visit the site in archive.org and more

  • Search Tools
    • Free eBook Search
      • Search with the highlighted text for your favorite free ebooks in www.freebookzone.com by title, author, description, ISBN and other terms

    • Hyperwords
      • Click on text for searches, references, email, blogging, translation, shopping, maps & more

    • Cache View
      • Displays Google’s Cache, Coral’s Cache, Wayback Machine’s Cache, Dot Cache, and Tech Guru’s Cache of the current tab open via right-click or Tools menu

    • Enhanced History Manager
      • Flexible history management

    • Enhanced Bookmark Search
      • Search by Title, Location, description or keyword including more subsets
        (contains, starts/ends with, is/is not, doesn’t contain)

    • GooglePedia
      • Shows you a relevant Wikipedia article along with your search results. Clicking links in the article will trigger new Google searches; a very useful research tool.

    • Google Advanced Operations Toolbar
      • This toolbar provides a shortcut to some of Google’s advanced search functions

  • Tabbed Browsing
    • Tab Mix Plus
      • Includes such features as duplicating tabs, controlling tab focus, tab clicking options, undo closed tabs and windows, restoring tabs after a crash and more

    • Sage RSS Reader
      • Sage is a lightweight RSS and Atom feed aggregator extension for Mozilla Firefox

    • Sidebar on Right
      • Moves sidebar to the right side of the browser

    • Firefox Showcase
      • Showcase provides a new way to manage your Firefox tabs and windows by showing them as thumbnails in a single window, tab or sidebar

  • Web Annoyances
  • Website Integration
  • XUL Applications
  • Miscellaneous Extensions
    • ForecastFox
      • Get international weather forecasts from AccuWeather.com, and display it in any toolbar or statusbar with this highly customizable extension.

    • Blogger Web Comments
      • Makes it easy to see what bloggers are saying about a web page you’re viewing in Firefox and even write your own blog post about it, all without leaving the page itself.

    • FasterFox
      • Allows you to tweak many network and rendering settings such as simultaneous connections, pipelining, cache, DNS cache, and initial paint delay.

    • Shazou
      • Enables the user with one-ckick to map and geo-locate any website they are currently viewing.

What is in Firefox 2.0 and Beyond

  • Visual changes to the Firefox interface
  • Built-in phishing protection
  • Enhanced search capabilities
  • Improved tabbed browsing
  • Resuming your browsing session
  • Previewing and subscribing to Web feeds
  • Inline spell checking
  • Live Titles
  • Improved Add-ons manager
  • JavaScript 1.7
  • Extended search plugin format
  • Updates to the extension system
  • Client-side session and persistent storage
  • SVG text
  • New Windows installer

All of the information here was taken from a pair of Impress presentations that David had made for the presentation.

The next meeting is scheduled for January 4th at 7PM at NFA. At this meeting Dave is going to be doing a presentation on Bash. The pre-meeting dinner will most likely be at Dillans in Norwich starting at 6PM.