Work Work Work!


del.icio.us:Work Work Work! digg:Work Work Work! spurl:Work Work Work! wists:Work Work Work! simpy:Work Work Work! newsvine:Work Work Work! blinklist:Work Work Work! furl:Work Work Work! reddit:Work Work Work! fark:Work Work Work! blogmarks:Work Work Work! Y!:Work Work Work! smarking:Work Work Work! magnolia:Work Work Work! segnalo:Work Work Work!

For this exercise, I will be basing my walk through off of AVR Freak’s Wiki documentation. For other updating options, please refer to the Firmware Upgrade page on AVR Freak’s Wiki.

Using NGW100’s Root FS & WGET to Load /usr FS

  1. Get booted all the way into the root filesystem on the NGW100.
  2. Run ps at the root prompt. You will be shown a list of all running processes on the NGW100.
  3. We must kill all processes running from /usr. Here is the command I used: killall dnsmasq telnetd inetd httpd dropbear nmbd
  4. Now issue umount /usr to unmount the partition. If it fails, you still have something running for the /usr partition. Check ps.
  5. Now we erase the /usr partition, otherwise known as /dev/mtd3 by issuing flash_eraseall /dev/mtd3.
  6. Once that is finished, we need to make sure we are in root (/) directory. Run cd ~ just to make sure.
  7. Now we download the usr image with
del.icio.us:NGW100: Restore or Upgrade Usr Filesystem With WGET digg:NGW100: Restore or Upgrade Usr Filesystem With WGET spurl:NGW100: Restore or Upgrade Usr Filesystem With WGET wists:NGW100: Restore or Upgrade Usr Filesystem With WGET simpy:NGW100: Restore or Upgrade Usr Filesystem With WGET newsvine:NGW100: Restore or Upgrade Usr Filesystem With WGET blinklist:NGW100: Restore or Upgrade Usr Filesystem With WGET furl:NGW100: Restore or Upgrade Usr Filesystem With WGET reddit:NGW100: Restore or Upgrade Usr Filesystem With WGET fark:NGW100: Restore or Upgrade Usr Filesystem With WGET blogmarks:NGW100: Restore or Upgrade Usr Filesystem With WGET Y!:NGW100: Restore or Upgrade Usr Filesystem With WGET smarking:NGW100: Restore or Upgrade Usr Filesystem With WGET magnolia:NGW100: Restore or Upgrade Usr Filesystem With WGET segnalo:NGW100: Restore or Upgrade Usr Filesystem With WGET

Next I am going to look at using TFTP to restore or upgrade the /root filesystem on the NGW100. The /root file system will require more intereaction with U-Boot so let us get started!

For this exercise, I will be basing my walk through off of AVR Freak’s Wiki documentation. For other updating options, please refer to the Firmware Upgrade page on AVR Freak’s Wiki.

Quick TFTP Setup

  1. Open a console on your Ubuntu development desktop.
  2. Run sudo apt-get install tftpd to install the tftp server.
  3. Make sure /srv/tftp exists on the desktop system.
  4. Restart tftpd with /etc/init.d/openbsd-inetd restart.
  5. Download the /root filesystem (rootfs.avr32.jffs2-root) from atmel.no.
    Note: Make sure you grab the right version to match u-boot.
  6. Copy this file to your TFTP server directory (/srv/tftp). You are ready to go!

Using U-Boot and TFTP To Restore The Root Filesystem

This section assumes that your Linux desktop is not your DHCP server. I don’t know too many people who would have this setup normally so why even bother screwing with that when its quite easy to type a few extra lines and get the same results.

  1. Make sure your desktop and NGW100 are connected via serial cable and that you are connected via a terminal program. Also connect and ethernet cable between the NGW100’s WAN port and your network. Power the NGW100 on if needed.
  2. If you only have U-Boot installed, you will end up at a Uboot> prompt. If not watch carefully when the board frist starts.
    Note: There is a line mentioning that you have one second to hit space. Doing so will drop you to U-boot. 
  3. You can run the command dhcp real quick to have uboot grab an ip address for your ethernet connection.

    You may get an error saying that ethaddr is not set. So we will set a bogus mac address for the the NGW100 as follows:
    Uboot> set ethaddr 00:11:95:00:00:00

  4. If NGW100 did not get an IP from your DHCP server, run this line.

    Uboot> set ipaddr 192.168.100.105
    Set to an IP that is available on your network

  5. Now we set the rest of the important environment variables for TFTP.

    Uboot> set tftpip 192.168.100.103
    Change to your TFTP Server IP
    Uboot> set serverip 192.168.100.103
    Change to your TFTP Server IP
    Uboot> tftp
    This command will fail because you did not specify a file but it should show that it connected to the TFTP server and tried to download a file. If it did try to load one, you are ready to actually erase the existing root image. I personally find the above test methods much better then erasing the flash first before knowing you can get to the file.

  6. Now we are ready to flash the root filesystem to the NGW100 as follows:

    Uboot> protect off 0×20000 0×7EFFFF
    This turns off /dev/mtd1 flash protection.
    Uboot> erase 0×20000 0×7EFFFF
    This erases the entire /dev/mtd1 flash chip.
    Uboot> tftp 0×90000000 rootfs.avr32.jffs2-root
    This connects to your TFTP server, downloads the root image file and places it into SDRAM for temporary storage.
    Uboot> cp.b $(fileaddr) 0×20000 $(filesize)
    This copies the file (fileaddr) located in SDRAM to the start of the /dev/mtd1 flash chip and it also specifies its size. These two variables are added to the environment when you ran tftp above.
    Uboot> protect on all
    Turns read only protection back on for /dev/mtd1.

  7. Now just reboot your NGW100 and watch as Linux loads!
    Note: If you are upgrading the root filesystem from an older version, you will notice that the SYS LED now blinks red. This is normal. It represents the CPU’s heartbeat. No need to freak out (I know I did at first)!

Note: The first time I tried to boot the root filesystem, I got some unexpected errors. For more information check here.

That wasn’t too difficult. Next we will use WGET to load the /usr filesystem.

del.icio.us:NGW100: Restore or Upgrade Root Filesystem With TFTP digg:NGW100: Restore or Upgrade Root Filesystem With TFTP spurl:NGW100: Restore or Upgrade Root Filesystem With TFTP wists:NGW100: Restore or Upgrade Root Filesystem With TFTP simpy:NGW100: Restore or Upgrade Root Filesystem With TFTP newsvine:NGW100: Restore or Upgrade Root Filesystem With TFTP blinklist:NGW100: Restore or Upgrade Root Filesystem With TFTP furl:NGW100: Restore or Upgrade Root Filesystem With TFTP reddit:NGW100: Restore or Upgrade Root Filesystem With TFTP fark:NGW100: Restore or Upgrade Root Filesystem With TFTP blogmarks:NGW100: Restore or Upgrade Root Filesystem With TFTP Y!:NGW100: Restore or Upgrade Root Filesystem With TFTP smarking:NGW100: Restore or Upgrade Root Filesystem With TFTP magnolia:NGW100: Restore or Upgrade Root Filesystem With TFTP segnalo:NGW100: Restore or Upgrade Root Filesystem With TFTP

I did run into a bit of a problem after restoring u-boot and the root filesystem with the JTAG ICE. It appears that the version the board shipped with was setup to boot the linux kernel off of /dev/mtdblock1 at /uImage but the latest build, 2.3.0, had the kernel located at /boot/uImage. I was constantly getting the following error from u-boot:

Wrong Image Format for bootm command
ERROR: can’t get kernel image!
UBoot>

After a bit of Googling, I found a blog on the subject which suggested the following:

Booting By Internal Flash

To boot the kernel and root file system off of the internal flash (/dev/mtd1), get into u-boot and enter this:

Uboot> askenv bootcmd
Please enter ‘bootcmd’: fsload /boot/uImage; bootm
Uboot> askenv bootargs
Please enter ‘bootargs’: console=ttyS0 root=/dev/mtdblock1 rootfstype=jffs2
Uboot> saveenv
Uboot> bootm

Booting By SD Card

To boot the kernel and root file system off of SD card (/dev/mmcblk0p1), get into u-boot and enter this:

Uboot> askenv bootcmd
Please enter ‘bootcmd’: mmcinit; ext2load mmc 0:1 0×103000000 /boot/uImage; bootm 0×103000000
Uboot> askenv bootargs
Please enter ‘bootargs’: console=ttyS0 root=/dev/mmcblk0p1 rootwait
Uboot> saveenv
Uboot> bootm

You can test to see if u-boot can read the card by issueing the command ext2ls mmc 0:1. It should list all of the files on the card.

I did notice while I was looking around that if you have problems on the NGW100 board with the above SD u-boot settings, that it is recommended to try setting rootwait to rootwait=1. Hope that will help someone else.

del.icio.us:NGW100 Error: UBoot Can't Get Kernel Image! digg:NGW100 Error: UBoot Can't Get Kernel Image! spurl:NGW100 Error: UBoot Can't Get Kernel Image! wists:NGW100 Error: UBoot Can't Get Kernel Image! simpy:NGW100 Error: UBoot Can't Get Kernel Image! newsvine:NGW100 Error: UBoot Can't Get Kernel Image! blinklist:NGW100 Error: UBoot Can't Get Kernel Image! furl:NGW100 Error: UBoot Can't Get Kernel Image! reddit:NGW100 Error: UBoot Can't Get Kernel Image! fark:NGW100 Error: UBoot Can't Get Kernel Image! blogmarks:NGW100 Error: UBoot Can't Get Kernel Image! Y!:NGW100 Error: UBoot Can't Get Kernel Image! smarking:NGW100 Error: UBoot Can't Get Kernel Image! magnolia:NGW100 Error: UBoot Can't Get Kernel Image! segnalo:NGW100 Error: UBoot Can't Get Kernel Image!

So as I mentioned, I attempted the flash method to update u-boot to the latest version. I got to the erase flash part of the instructions and I ended up getting a support call and had to run. Storm rolled through while I was gone and killed the power and, because it was down for more than an hour, the battery backup too. So I returned home to find a ‘dead’ NGW100 board.

Just to mention, there are three ways to perform a NGW100 U-Boot/Root FS update. They are as follows:

  • Update through u-boot itself
  • Update using Atmel’s flash-update program
  • Update with the JTAG ICE MKII (which I will demonstrate)
  • You can also update the root filesystem via SD Card, Network, Serial, or JTAG. I decided to use JTAG ICE to restore both U-Boot and the root filesystem.

For this exercise, I will be basing my walk through off of AVR Freak’s Wiki documentation. For other updating options, please refer to the Firmware Upgrade page on AVR Freak’s Wiki.

Notes

  • U-Boot is stored in /dev/mtd0. Its partition is from 0×000000 - 0×01FFFF.
  • Root Filesystem is stored in /dev/mtd1. Its partition is from 0×020000 - 0×7EFFFF.
  • The U-Boot environment area (used for storing environmental variables for U-Boot) is located in /dev/mtd2. Its partition is from 0×7F0000 - 0×7FFFFF.
  • Usr Filesystem is stored in /dev/mtd3.
  • If you have an old root image. Do not worry if the system light blinks red after updating. The code in the kernel has changed to represent a cpu heartbeat and is normal.

After purchasing the JTAG ICE MKII and after setting up Ubuntu with a AVR32 development environment, I did the following to replace u-boot.

Prepare NGW100 For JTAG ICE Restore

  1. Remove power to the NGW100 board.
  2. Connect the JTAG ICE MKII to power and connect a USB cable between Linux and the programmer.
  3. Make sure the JTAG ICE power is off. Now connect the JTAG connector to the NGW100 (I’ve included a picture above with the correct way to plug the connector into the NGW100.
  4. Now power the JTAG ICE device. If you check /var/log/messages on your Linux box, you should see that your system detected the JTAG programmer.
  5. Now apply power to the NGW100.
  6. Go to atmel.no/buildroot/binaries and pick the latest version. I downloaded the following files from version 2.3.0: u-boot.bin and root.avr32.jffs2-root.
  7. Next we restore u-boot with the JTAG ICE

Picture of the actual JTAG ICE connector. The NGW100 uses the smaller green connector.

Use JTAG ICE To Flash U-Boot and Root On The NGW100

  1. First we erase the entire flash of the NGW100 board with sudo avr32program erase -fcfi@0 to ensure the board is clear.
  2. Now we flash the u-boot image onto the NGW100 board with sudo avr32program program -F bin -vfcfi@0 u-boot.bin.
  3. Now we flash the root image onto mtd1 with sudo avr32program program -F bin -vfcfi@0 -O 0×20000 root.avr32.jffs2-root.
  4. All done! Unplug the power from the NGW100 and turn off the JTAG ICE MKII.
  5. Disconnect the JTAG connector from the NGW100.
  6. Plug in your NGW100 board and watch it fly.

Note: The first time I tried to boot the root filesystem, I got some unexpected errors. For more information check here.

That is how you use a JTAG ICE MKII to restore/upgrade/install a fresh u-boot and root image onto your Atmel NGW100 board. You can also use TFTP to load a root image or you can move on to loading the usr filesystem.

del.icio.us:Recover Broken NGW100 U-Boot With JTAG ICE MKII digg:Recover Broken NGW100 U-Boot With JTAG ICE MKII spurl:Recover Broken NGW100 U-Boot With JTAG ICE MKII wists:Recover Broken NGW100 U-Boot With JTAG ICE MKII simpy:Recover Broken NGW100 U-Boot With JTAG ICE MKII newsvine:Recover Broken NGW100 U-Boot With JTAG ICE MKII blinklist:Recover Broken NGW100 U-Boot With JTAG ICE MKII furl:Recover Broken NGW100 U-Boot With JTAG ICE MKII reddit:Recover Broken NGW100 U-Boot With JTAG ICE MKII fark:Recover Broken NGW100 U-Boot With JTAG ICE MKII blogmarks:Recover Broken NGW100 U-Boot With JTAG ICE MKII Y!:Recover Broken NGW100 U-Boot With JTAG ICE MKII smarking:Recover Broken NGW100 U-Boot With JTAG ICE MKII magnolia:Recover Broken NGW100 U-Boot With JTAG ICE MKII segnalo:Recover Broken NGW100 U-Boot With JTAG ICE MKII

Over the past few days I attempted to upgrade the u-boot, root, and usr images on my NGW100 but ended up loosing power after erasing the u-boot partition (doh, major fail!). I ended up realizing that Mouser Electronics was pretty close to me in Ft Worth so I ran over there earlier this week and plunked down the $300 (another doh!) for a JTAG ICE MKII Programmer. I really didn’t want to spend that much money, but I figure it will come in handy during future development.

So this post starts out with a wiped NGW100 board, a JTAG ICE MKII, and a spare computer I had laying around. I decided to use the spare computer to setup a proper development platform as I really needed to get away from Windows. I did try to run the Atmel Ubuntu VMWare image, but it ran very slow and VMware Player somehow killed the drivers for my wireless card on my laptop. So for this post, I will go over the steps I took to setup Ubuntu and install all of the necessary files needed to setup an AVR development environment.

Installing Ubuntu

  1. Went to Ubuntu.com and downloaded a copy of Ubuntu 9.04 Desktop.
  2. Once finished, I burned the ISO to a CD and booted the install disk up on the desktop.
  3. As long as you do not have a strange setup on your computer, the install should be a breeze. It felt like I was installing Windows (as in very little options I had to screw with).
    Note: I’m not going to go into the details of setting up Ubuntu as I am wanting to concentrate on the AVR board here.

Installing The AVR Development Environment

The following information was found off of the AVR Freaks Wiki::Documentation:AVR32 General/Installing tools on Ubuntu Linux. I have sort of repeated it due to a few differences I noticed on my machine.

  1. Start by adding deb http://www.atmel.no/avr32/ubuntu/hardy binary/ to your /etc/apt/sources.list file.
  2. Then run sudo apt-get update to grab the package lists off of the atmel site.
  3. Note: Now I had to install libxerces27 but was unable to find it through the default apt sources nor the atmel site. This may be due to my setup running Ubuntu 9.04 Desktop vs the AVR Freak directions being for 8.04.

    To get this file, go to the Ubuntu Packages site and download libxerces27 here.

  4. Once it is downloaded, go to the directory and run dpkg -i libxerces27-dev_2.7.0-5_i386.deb to install libxerces27.
  5. Once that is done, you need to install some prerequisite tools. Run sudo apt-get install avr32program avr32gdbproxy avr32trace avrfwupgrade libavr32ocd libavrtools libelfdwarfparser to get the needs packages.
  6. And finally, we install the AVR32 Toolchain by running sudo apt-get install avr32-gnu-toolchain.
  7. We’re done. Optionally, you may want to create a local repository of the BSP CD.

I will be coming back to this in a bit to build my first NGW100 image, so this info may change.

del.icio.us:Setting Up Ubuntu For AVR32 Development digg:Setting Up Ubuntu For AVR32 Development spurl:Setting Up Ubuntu For AVR32 Development wists:Setting Up Ubuntu For AVR32 Development simpy:Setting Up Ubuntu For AVR32 Development newsvine:Setting Up Ubuntu For AVR32 Development blinklist:Setting Up Ubuntu For AVR32 Development furl:Setting Up Ubuntu For AVR32 Development reddit:Setting Up Ubuntu For AVR32 Development fark:Setting Up Ubuntu For AVR32 Development blogmarks:Setting Up Ubuntu For AVR32 Development Y!:Setting Up Ubuntu For AVR32 Development smarking:Setting Up Ubuntu For AVR32 Development magnolia:Setting Up Ubuntu For AVR32 Development segnalo:Setting Up Ubuntu For AVR32 Development

For my first few posts on the NGW100, I am going to start with a walk through on compiling a new kernel and root image for the device. This will give me a better understanding of the differences between the AP7000 vs the x86 platform when it comes to Linux and compiling its software. My main goal is to understand more about how programs are compiled and prepared to run on the Atmel platform so that when I get to my end goal, installing Asterisk/AstLinux, I have a better grasp of this platform.

Useful Notes

Here are some useful notes I’ve realized throughout the process. Might as well get these out of the way before continuing.

  • The boot select jumper currently has no use. It was built into the board for future Atmel/third party development and currently has no barring on anything.
  • To get to Uboot, you must be connected with a serial cable/terminal and must hit space when you see ‘Press SPACE to abort autoboot in 1 seconds‘ at the beginning of boot to get to this menu.
  • The kernel/root image can be upgraded/changed by using a TFTP server or by using an SD card (I will be attempting the later through this walk through).
  • - many more I’m sure -

Backing Up The Original Atmel Linux Image

Okay the following section is all hear-say. I played around for a long time in Uboot looking for a way to dump the data flash and flash chips to an image on my TFTP server and was unsuccessful. So I did the next best thing…I dd and cp -paR -ed the hell out of the system. Here is what I did, there may be an easier way:

  1. Inserted blank 512MB SD Card (vfat, who cares) into NGW100 and booted it up.
  2. Did a quick cat /etc/fstab to get an idea of what devices I needed to backup. I ignored all of the virtual directories like /var, /proc, /dev, etc.
  3. Attempted to run dd -if=/dev/mtdblock -of=/media/[sd card name]/filesystem.img but got an error that the device did not exist.
    • Note: My best guess on this is that the system does not look at both flash chips as one but as separate entities, but, I’m new at this so I have no idea and had to move on to the next best thing.
  4. Ran dd -if=/dev/mtdblock1 -of=/media/[sd card name]/root.img
    • Note: This is the / mount on my system. came out to 8MB which would be about one of the flash chips.
  5. Ran dd -if=/dev/mtdblock3 -of=/media[sd card name]/usr.img.
    • Note: This is the /usr mount on my system. came out to 8MB which would be about one of the flash chips.
  6. I then also ran unknown image backups on /dev/mtdblock0 and mtdblock2 with the hope of grabbing Uboot or anything else I may have missed. /dev/mtdblock5+ was non existent.
  7. I then copied the kernel image with cp -paR uImage /media[sd card name]/. I also copied /etc, /config, /lib, and /usr again just to be safe.
  8. Unmounted the SD Card with umount /media/[sd card name], ejected, labeled it, and placed it in safe keeping.

All this was done as I managed to hit 1.3 GB on the BSP package. If anyone has some incite on an easier/quicker way to backup the original image, please let me know. I will mention right now that I do not have a JTAG lying around. Planning on going to Mouser Electronics in Ft Worth to build/buy one tomorrow if time permits.

Next up, I will attempt to upgrade Uboot I believe.

del.icio.us:Backing Up The Original BusyBox Image On The NGW100 digg:Backing Up The Original BusyBox Image On The NGW100 spurl:Backing Up The Original BusyBox Image On The NGW100 wists:Backing Up The Original BusyBox Image On The NGW100 simpy:Backing Up The Original BusyBox Image On The NGW100 newsvine:Backing Up The Original BusyBox Image On The NGW100 blinklist:Backing Up The Original BusyBox Image On The NGW100 furl:Backing Up The Original BusyBox Image On The NGW100 reddit:Backing Up The Original BusyBox Image On The NGW100 fark:Backing Up The Original BusyBox Image On The NGW100 blogmarks:Backing Up The Original BusyBox Image On The NGW100 Y!:Backing Up The Original BusyBox Image On The NGW100 smarking:Backing Up The Original BusyBox Image On The NGW100 magnolia:Backing Up The Original BusyBox Image On The NGW100 segnalo:Backing Up The Original BusyBox Image On The NGW100

After a long hiatus, I’m back! Work has been crazy, but I may have a bit more time on my hands now. To get things off to a good start, I purchased an Atmel NGW 100 Embedded Linux demo board the other day. I have been drooling over the idea of integrating circuit design with the Linux operating system for some time and at a cost of $70-$80, its a steal.

Picture of the product.
The Atmel NGW100 with its box.

The Atmel NGW100 Close Up.

The Atmel NGW100 board  which measures in at 120mm by 100mm comes with the AT32AP7000 processor which runs at 130 MHz (150MHz overclocked). It also has 16MB of flash memory, 32MB of SDRAM, SD Card reader for storage, 2 10/100 ethernet controllers, a serial and a USB connection. It appears to come pre-installed with a nice copy of the BusyBox Linux distro on it which includes command line tools, SSH, a web server, NFS and Samba.

I found a very interesting project for this board on Sawdust’s Blog called ‘Network Accessible A/C Outlet Control‘. You can also find a lot of useful information on this board at AVRfreaks and on their NGW 100 Documentation Wiki.

I think I am going to recreate Sawdust’s device first just to play around and get use to it. After that, I am really interested in trying to get Asterisk loaded onto the board. I am figuring that with the overclocked processor, I should be able to squeeze 2-4 VoIP lines out of it. From what I’ve found out so far though, it is going to be a real pain to get Asterisk’s voice codecs compiled to run on the Atmel processor. Oh well, if it isn’t challenging, it isn’t fun!

Besides playing with the NGW100, I will also get back to work on XBee, home automation, and a lot more VoIP/Asterisk stuff. I’ll keep everyone updated.

del.icio.us:Atmel NGW100 Linux Embedded Network Gateway digg:Atmel NGW100 Linux Embedded Network Gateway spurl:Atmel NGW100 Linux Embedded Network Gateway wists:Atmel NGW100 Linux Embedded Network Gateway simpy:Atmel NGW100 Linux Embedded Network Gateway newsvine:Atmel NGW100 Linux Embedded Network Gateway blinklist:Atmel NGW100 Linux Embedded Network Gateway furl:Atmel NGW100 Linux Embedded Network Gateway reddit:Atmel NGW100 Linux Embedded Network Gateway fark:Atmel NGW100 Linux Embedded Network Gateway blogmarks:Atmel NGW100 Linux Embedded Network Gateway Y!:Atmel NGW100 Linux Embedded Network Gateway smarking:Atmel NGW100 Linux Embedded Network Gateway magnolia:Atmel NGW100 Linux Embedded Network Gateway segnalo:Atmel NGW100 Linux Embedded Network Gateway

I was looking around on the web the other day for an easy way to backup data on a Linux server to Amazon S3. I ended up running into SoftwareBloat’s script and liked what they had done with it. One thing I needed, however, was to be able to clean up the backup bucket on S3. So here is the script i came up with from SoftwareBloats original. Hope it will help someone looking for the same!

Oh one note, after you issue the apt-get install s3cmd command to grab the program, you will also want to run s3cmd –configure which will ask for your S3 information. Important step before the below will work.

#!/bin/bash
## SoftwareBloat’s Script
## TheKidd had to play with it.
## Which means I screwed it up.
## Hehe, thx bloat! Awesome tutorial! Hope this might help.

# Dates to variables for the backup script
DATE_TAG=$(date +"%Y.%m.%d")
# to clean backups off s3 older than 28 days
# as i only want to keep 4 sets of backups
S3_DATE_TAG=$(date -d "-28 days" +"%Y.%m.%d")

# Admin email notification
EMAIL_ADMN="admin@domain.com"
EMAIL_SUBJ="S3 Backup Results"
EMAIL_FROM="s3backup@domain.com"

# Directories to backup to and from
SHELL_DIR="/shell"
WWW_DIR="/www"
HOME_DIR="/home"
ROOT_DIR="/root"
BACKUP_DIR="/backup/soho"

SQL_BK_NAME="athena.mysql.bk"
BUCKET_NAME="sohobackup"

# Intro for Admin Email
echo "This message is to inform you that your backup on $DATE_TAG just started running. Lets get started." > $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1

# Clean up any files older than 7 days
# this allows me to catch the 7 daily mysql backups but delete anything created 8+ days ago.
echo "Cleaning folders before start…" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
/usr/bin/find $BACKUP_DIR -maxdepth 0 -type f -mtime +7 -print | xargs rm -f

# backup key directories
echo "Backing up key directories…" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
tar pczvf $BACKUP_DIR/shell-$DATE_TAG.tgz $SHELL_DIR
tar pczvf $BACKUP_DIR/www-$DATE_TAG.tgz $WWW_DIR
tar pczvf $BACKUP_DIR/home-$DATE_TAG.tgz $HOME_DIR
tar pczvf $BACKUP_DIR/root-$DATE_TAG.tgz $ROOT_DIR

# backup databases
# echo "Backing up Database…" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
# mysqldump -u root –password=your_pw_here –all-databases | gzip -c > $BACKUP_DIR/$SQL_BK_NAME$DATE_TAG.gz
# **Don’t need the above as webmin provides daily MySql backups dumped into BACKUP_DIR**
# But everyone prefers their own way!

# Just to prevent errors, we attempt to create the bucket
/usr/bin/s3cmd -c /root/.s3cfg mb s3://$BUCKET_NAME

# Backup all the tgz’s with correct date stamp
echo "Uploading backup files…" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
for f in $BACKUP_DIR/*$DATE_TAG.tgz
do
    /usr/bin/s3cmd -c /root/.s3cfg put $f s3://$BUCKET_NAME/$(basename $f) >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
done

# now we kill the mysql daily backups made 28+ days ago
echo "Deleting old DB files on S3…" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
for (( i=40; i>=28; i– ))
do
   /usr/bin/s3cmd -c /root/.s3cfg del s3://$BUCKET_NAME/$SQL_BK_NAME`date -d "-$i days" +"%Y.%m.%d"`.tgz >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
done

# now we kill the key directory backups made 28+ days ago
echo "Deleting old key directories on S3…" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
for f in shell www home root
do
   /usr/bin/s3cmd -c /root/.s3cfg del s3://$BUCKET_NAME/$(basename $f)-$S3_DATE_TAG.tgz >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
done

# just to let the admin in on the backup
echo "All done! Below is a list of what was backed up."
echo "Additional info: $BACKUP_DIR/logs/backup-$DATE_TAG.log" $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
/usr/bin/s3cmd -c /root/.s3cfg ls s3://$BUCKET_NAME/ >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1

echo "Sending Email! Have a good day!" >> $BACKUP_DIR/logs/backup-$DATE_TAG.log 2>&1
(echo "Subject: $EMAIL_SUBJ"; echo "From: $EMAIL_FROM"; echo "To: $EMAIL_ADMN";
echo "Reply-To: $EMAIL_FROM"; cat $BACKUP_DIR/logs/backup-$DATE_TAG.log;) | /usr/lib/sendmail -t

del.icio.us:Server Backups on Amazon's S3 digg:Server Backups on Amazon's S3 spurl:Server Backups on Amazon's S3 wists:Server Backups on Amazon's S3 simpy:Server Backups on Amazon's S3 newsvine:Server Backups on Amazon's S3 blinklist:Server Backups on Amazon's S3 furl:Server Backups on Amazon's S3 reddit:Server Backups on Amazon's S3 fark:Server Backups on Amazon's S3 blogmarks:Server Backups on Amazon's S3 Y!:Server Backups on Amazon's S3 smarking:Server Backups on Amazon's S3 magnolia:Server Backups on Amazon's S3 segnalo:Server Backups on Amazon's S3

Quick Update

I’ve been so bad in the past few months about updating this blog. I’ve made some headway so far on my latest project, but it has not been what I’ve would have liked. Been side tracked due to a great idea I had for a program in C# for insurance agencies.

Thanks to everyone who have sent me feedback from the Arudino/Make forums. I definitely need to update some previous posts with your suggestions along with some new ideas and accomplishments I’ve been able to pull off. I’ll get on this as soon as possible. Its just so difficult between the IT company and the software program I’ve been developing.

I’ll do my best to post soon. Definitely let me know if you find any problems so far with my posts. I appreciate the feedback.

del.icio.us:Quick Update digg:Quick Update spurl:Quick Update wists:Quick Update simpy:Quick Update newsvine:Quick Update blinklist:Quick Update furl:Quick Update reddit:Quick Update fark:Quick Update blogmarks:Quick Update Y!:Quick Update smarking:Quick Update magnolia:Quick Update segnalo:Quick Update

Next »