thiagobraga
4/26/2014 - 6:06 PM

Bash aliases

Bash aliases

# Import Barpedia database locally
# ==========================================
#
# Exports the barpedia.org production database,
# creates a symlink to exported file to make possible
# download via HTTP using Axel and install locally.
barpedia_backup () {
    echo 'Exportando banco de dados do Barpedia. Aguarde alguns instantes...'
    ssh barpedia "
        mysqldump -u'root' -p'am0s r3c4d' \
            --default-character-set='utf8' \
            --databases barpedia_production \
            --add-drop-database \
            --skip-quote-names \
            --skip-add-locks \
            --skip-comments \
            --set-charset \
            --triggers \
            -R -C -q > /var/www/backup/barpedia/barpedia_production.txt
        sed -i 's/barpedia_production/barpedia_testing/g' /var/www/backup/barpedia/barpedia_production.txt
        if [ ! -h /var/www/barpedia/release/barpedia_production.txt ]; then
            ln -s /var/www/backup/barpedia/barpedia_production.txt /var/www/barpedia/release/barpedia_production.txt
        fi
        exit"

    echo 'Fazendo download do arquivo SQL.'
    axel -q -n 50 http://release.barpedia.org/barpedia_production.txt

    echo 'Importando banco de dados localmente...'
    cd /var/www/barpedia && r=$(./install.sh restore barpedia_production.txt)

    echo 'Excluindo arquivo de backup no local e no DigitalOcean.'
    rm /var/www/barpedia/barpedia_production.txt
    ssh barpedia "
        rm /var/www/barpedia/release/barpedia_production.txt
        rm /var/www/backup/barpedia/barpedia_production.txt
        exit"

    echo 'Reiniciando mysql após a importação.'
    sudo service mysql restart

    echo 'Importação finalizada!'
}


# Import Barpedia db on testing environment
# ==========================================
#
# Exports the barpedia.org production database
# and imports in the development database, both in DigitalOcean.
barpedia_backup_dev () {
    ssh barpedia 'r=$(mysqldump -u"root" -p"am0s r3c4d" --default-character-set="utf8" --databases barpedia_production --add-drop-database --skip-quote-names --set-charset --triggers -R -C -q > /var/www/backup/barpedia/barpedia_production.txt); sed -i "s/barpedia_production/barpedia_testing/g" /var/www/backup/barpedia/barpedia_production.txt; r=$(/var/www/barpedia/master/install.sh restore /var/www/backup/barpedia/barpedia_production.txt); rm /var/www/backup/barpedia/barpedia_production.txt; exit'
}


# Aliases
# ==========================================
alias barpedia-backup="barpedia_backup"
alias barpedia-backup-dev="barpedia_backup_dev"

# Git
alias gmff='git merge --no-ff --no-edit'



alias n='nano -c --tabstospaces --tabsize=4 --morespace --smooth'