<commit_before>#!/bin/sh -x

umask 077
max_backup_keep=2

function do_db_backup() {
    config_file=$1
    backup_path=$2
    environment=$3

    #gets a field from database.yml
    function get_field () {
      line=`grep $1 $config_file` #grep the line
      value=${line##*:} #get the value
      value=`echo $value | tr -d ''` #remove all white spaces
      echo $value
    }

    function trim_backups {
	arch_files=(`ls -rt $backup_path`) #reverse list of files in an array
        count=${#arch_files[@]}
	if [ $count -gt $max_backup_keep ]
	   then
               del_count=`expr $count - $max_backup_keep`
	       del_count=`expr $del_count - 1` #normalize for zero based array
               for i in $(seq 0 $del_count)
                 do
                   rm $backup_path/${arch_files[$i]}
                 done
        fi
    }
    
    pwd=`get_field password`
    databse=`get_field database`
    user=`get_field username`
    database=`get_field database`

    date=`date '+%Y-%m-%d_%H:%M:%S'`
    backup_file=database_${environment}_${database}_$date.bz2

    /usr/bin/mysqldump -u $user --password=$pwd --databases $database | /usr/bin/bzip2 -9 > $backup_path/$backup_file
    trim_backups
}

### DO  ####
do_db_backup database.yml backups_location custom_envname

<commit_msg>minor modifications<commit_after>#!/bin/bash

umask 077
max_backup_keep=30

function do_db_backup () {
    config_file=$1
    backup_path=$2
    environment=$3

    #gets a field from database.yml
    function get_field () {
      line=`grep $1 $config_file` #grep the line
      value=${line##*:} #get the value
      value=`echo $value | tr -d ''` #remove all white spaces
      echo $value
    }

    function trim_backups () {
	arch_files=(`ls -rt $backup_path`) #reverse list of files in an array
        count=${#arch_files[@]}
	if [ $count -gt $max_backup_keep ]
	   then
               del_count=`expr $count - $max_backup_keep`
	       del_count=`expr $del_count - 1` #normalize for zero based array
               for i in $(seq 0 $del_count)
                 do
                   rm $backup_path/${arch_files[$i]}
               done
        fi
    }
    
    pwd=`<PASSWORD>`
    databse=`get_field database`
    user=`get_field username`
    database=`get_field database`

    date=`date '+%Y-%m-%d_%H:%M:%S'`
    backup_file=daily_db_${environment}_${database}_$date.bz2

    /usr/bin/mysqldump -u $user --password=$<PASSWORD> --databases $database | /usr/bin/bzip2 -9 > $backup_path/$backup_file
    trim_backups
}

do_db_backup database.yml db_backups production

{'fraction_non_alphanumeric': 0.12572759022118743, 'fraction_numerical': 0.010477299185098952, 'mean_word_length': 2.5905292479108635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6418008', 'n_tokens_mistral': 904, 'n_tokens_neox': 848, 'n_words': 204}