Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
7 total  XML / RSS feed 

Postgresql dump SS archive script

Dump, bzip, and upload a postgres database to strongspace. Via Ubernostrum


FILENAME=b_list-`/usr/xpg4/bin/date +%Y%m%d`.sql.bz2
cd /home/myuser/dumps
/opt/local/bin/pg_dump -U db_username db_name | /usr/bin/bzip2 > $FILENAME
/usr/bin/scp $FILENAME me@strongspace:/my/backup/dir/

Complete backup of all domains to strongspace

# comprehensive TextDrive backup to Strongspace
# Joel Dueck (
# This script will backup all websites in your TextDrive account to Strongspace.
#         1. Save this script into your home dir,  chmod it to 700 for security
# 2. Create a pair of ssh keys; install the public key on your strongspace account and the private one in ~/.ssh
# 3. Change the configuration variables below

## Configuration section
#  [Don't forget trailing slashes for all directories!]


        # Optional: Enter the path in your TextDrive account where your database backups are stored.
        # If found, this directory will be rsync'd to strongspace separately. If this folder does not exist then 
        # this feature will be ignored.
        # For a cron job that will create daily rolling MySQL backups, see

        STRONGSPACE_KEY=/home/YOURUSERNAME/.ssh/ss             # Private key file
        STRONGSPACE_USER=SSUSER                                  # Your strongspace login name          # Your strongspace domain

        STRONGSPACE_WEB_BACKUP_DIR=private/backup/web/               # strongspace path for storing web file backups
        STRONGSPACE_DB_BACKUP_DIR=private/backup/databases/  # optional strongspace path for storing SQL backups
## End of configuration section

DOMAINS=`ls ~/domains`
for dom in $DOMAINS
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" ~/domains/$dom/public_html/ $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_WEB_BACKUP_DIR/$dom

if [ -d ~/public_html ]; then
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" ~/public_html/ $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_WEB_BACKUP_DIR/$dom

if [ -d $DB_BACKUP_DIR ]; then

Mount Strongspace to a folder in Ubuntu

1) Install the software
sudo apt-get install sshfs

2) Add fuse to /etc/modules
sudo nano /etc/modules

3) Add yourself to the 'fuse' group, then log out and log in again.
sudo adduser your-username fuse

4) Create a mountpoint and give yourself ownership
sudo mkdir /media/mount-name
sudo chown your-username /media/mount-name

5) Mount the filesystem
sshfs remote-system-name:/remote-folder /media/mount-name

6) Unmount the filesystem
fusermount -u /media/mount-name

Directions lifted from Ubuntu forums and here also.

For myself, I had better results running the following command in the same directory that the file that I mounted resides in...

sudo sshfs folder_name

Where folder_name is the name of the folder that you are mounting strongspace to.

Backup from textdrive to strongspace

# backup script for textdrive to strongspace based on these articles:

# change this!
PWD_MYSQL=somepassword # chmod 700 this file

# Backup database 
# copy this line for more databases or 
# use --all-databases if you are the main user
# Don't forget to change the database name
/usr/local/bin/mysqldump --opt --skip-add-locks --user=$USER --password=$PWD_MYSQL database1 | gzip > $HOME/backups/database1_`date "+%Y-%m-%d"`.gz
/usr/local/bin/mysqldump --opt --skip-add-locks --user=$USER --password=$PWD_MYSQL database2 | gzip > $HOME/backups/database2_`date "+%Y-%m-%d"`.gz

# Backup subversion (Only works with FSFS)
cd $HOME
tar -z -c -f $HOME/backups/svn_`date "+%Y-%m-%d"`.tar.gz svn

# Add custom dirs here, if you need it, just like the svn example above
# I just keep everything I need in subversion

# Delete old backups
cd $HOME/backups/
/usr/bin/find *.gz -mtime +8 -delete

# Send it to strongspace
/usr/local/bin/rsync -azq --delete -e "ssh -i $HOME/.ssh/ss" $HOME/backups/*.gz $USER_SS@$$USER_SS/txd-backup/

Daily rotated backups to Strongspace


# backup folder
MYSQL_DATABASES="db1 db2 dbn"
DIRS="dir1 dir2 dirn"
[email protected]

BACKUP_ALT=$(python -c "import time, sys; sys.stdout.write(str(int(time.strftime('%d')) % 2))")

for d in MYSQL_DATABASES; do
mysqldump --quick --opt --skip-add-locks $d |gzip - >${DEST}/${d}.sql.gz

for d in DIRS; do
tar zcvf ${HOME}${DEST}/${d}.tar.gz ${HOME}/${d} >/dev/null

scp -r ${DEST}/* ${STRONGSPACE_USER}:backup/$BACKUP_ALT/

rm -rf $DEST/*

Upload your Flickr photos to Strongspace

require 'net/http'
require 'rubygems'
require_gem 'flickr'
require_gem 'net-sftp'

flickr_username = "[email protected]"
flickr_pass = 'x'
strongie_pass = 'x'
strongie_username = 'johan'
strongie_upload_dir = "flickr_test"

flickr = 
flickr.login(flickr_username, flickr_pass)
user = flickr.users(flickr_username)

Net::SFTP.start("#{strongie_username}", strongie_username, strongie_pass) do |sftp|
  Net::HTTP.start('') do |http| do |photo|
      src_url = photo.source('Large').sub("", '')    
      puts "Fetching \"#{photo.title}\"..."
      res = http.get(src_url)
      filename = File.basename(src_url)
      sftp.open_handle("/home/#{strongie_username}/#{strongie_upload_dir}/#{filename}", 'w') do |handle|
        result = sftp.write(handle, res.body)
        puts "Wrote #{filename} with result code: #{result.code}..."

Rsyncing to StrongSpace

This is a handy script to synchronize a number of folders with StrongSpace (or any other server).


# `ss` is the alias for my StrongSpace login.
# `home/novemberborn/` is the directory in which I want to store stuff.
REMOTE = 'ss:/home/novemberborn/'

def rsync local_path, remote_dir
   puts `rsync -azv #{local_path} #{REMOTE}#{remote_dir}/`
   puts "\n---\n"

# rsync 'local_directory_path', 'remote_directory_name'
rsync '~/Documents/', 'Documents'
« Newer Snippets
Older Snippets »
7 total  XML / RSS feed