Affichage des articles dont le libellé est backup. Afficher tous les articles
Affichage des articles dont le libellé est backup. Afficher tous les articles

mercredi 24 mai 2017

Automatical periodic backup with simple bash script



Here is a very basic way to create a periodic backup of some of your folder in a LINUX environment

Create an cron file /etc/cron.montlhy/backup-tomcat

#!/bin/sh
SCOPE=monthly
tar -cvzf /mnt/nas/backup-tomcat/tomcat-`date +%Y%m%d`-$SCOPE.tgz -C/home/clement tomcat-8
find /mnt/nas/backup-tomcat/ -name \*$SCOPE\* -mtime +365 -exec rm -f {} \;

lundi 8 février 2016

Setup backup for SVN

Backup overview:

  • The maximum amount of work that you can afford to loose:
  • To define a backup policy you must define the maximum downtime:

 Backup specifics for source referential:

 When defining a backup policy, it is important to have some figures on the volume of data that you will generate, the data that you keep should be relevant, and best is to optimize the amount of data. Regarding this the configuration management has some specific because keeping a reasonable history is interesting.

 To setup a backup for SVN, there are basically two options
  • Generate an export from you repository using the svn export command. It has the advantage not to consider the big files that has been committed by error into the repository, but has the disadvantage to loose the history, but also duplicate all the information that has to do with the creation of branches or tags, resulting sometimes in making file bigger.
  • On the other hand you could use the svn dump functions svnadmin dump, that will keep the history and keep the links between the revision of trunk, but maybe this could be bigger in size (for instance if you did an import just at the beginning of the project and then you removed it), you do not want those file to consume some space. 
So the best option is to keep some of the history of the project, bu not all.
Here is a simple script that does it.


vi /etc/cron.daily/backup-svn-daily.sh

#/bin/sh
SVN_REPO_LOCATION=/var/svn-repo
rm -rf /tmp/svn/*>/dev/null
mkdir /tmp/svn

# Getting information on the last revision, filtering on line
# and cttuing the results
for i in $( find $SVN_REPO_LOCATION/* -maxdepth 0 -type d -printf "%f\n" ); do
        revmax=`svn info file://$SVN_REPO_LOCATION/$i/|grep Révision|cut -d ' ' -f 2|sed s/[a-z]*//`
        echo Revision max=$revmax
        revmin=$(expr $revmax - 100)
        revmin=$(( $revmin < 0 ? 0 : $revmin ))
        svnadmin dump -r$revmin:$revmax $SVN_REPO_LOCATION/$i>/tmp/svn/$i
        tar -czf /var/backup/$i-day-`date +%Y%m%d`.tgz /tmp/svn/$i
done
rm -rf /tmp/svn/*


find $BACKUP_LOCATION -name *day* -mtime +7 -exec grep rm -f {} \;


vi /etc/cron.weekly/backup-svn-weekly.sh
#/bin/sh
SVN_REPO_LOCATION=/var/svn-repo
BACKUP_LOCATION=/var/backup
rm -rf /tmp/svn/*>/dev/null
mkdir /tmp/svn
for i in $( find $SVN_REPO_LOCATION/* -maxdepth 0 -type d -printf "%f\n" ); do
        svnadmin dump $SVN_REPO_LOCATION/$i>/tmp/svn/$i
        tar -czf $BACKUP_LOCATION/$i-weekly-`date +%Y%m%d`.tgz /tmp/svn/$i
done
rm -rf /tmp/svn/*
find $BACKUP_LOCATION -name *weekly* -mtime +80 -exec grep rm -f {} \;



 vi /etc/cron.daily/clean-old-backup.sh
#!/bin/sh
find /var/backup/ -name *-day-* -mtime +7|xargs rm -f
find /var/backup/ -name *-week -mtime +30 |xargs rm -f



vendredi 3 octobre 2008

Astuces de backup sur Ubuntu et autres LINUX

Pour nettoyer automatiquement des répertoire de backup des fichiers top anciens

Mettez en cron la commande :

find  /var/backupreposvn/ -atime +60 -type f|xargs rm -f


Pour créer un backup de votre NAS sur votre ordinateur en ayant une gestion des backups trop ancien :


export BACKUPDIR=$HOME/backup/
mkdir $BACKUPDIR
export SRCFILE=$HOME/backup/`date +%Y%m%d`.tgz
tar -cvzf $SRCFILE $HOME/.gvfs/documents\ sur\ ls-wsglbc3/
export COMBIEN=`ls $BACKUPDIR|wc -l`
if [[ $COMBIEN>3 ]]
then
find $HOME/backup/ -mtime +30 -exec rm -f {} \;
else
echo "Pas de fichier à supprimer"
fi



My Sql

mysqldump -uroot -pjt ft_jobs_val|gzip >/var/backup/ft_jobs_val_`date +%Y%m%d`.dump.gz
mysqldump -uroot -pjt ft_jobs_val_int|gzip >/var/backup/ft_jobs_val_int_`date +%Y%m%d`.dump.gz
mysqldump -uroot -pjt jira1|gzip >/var/backup/ft_jobs_jira1_`date +%Y%m%d`.dump.gz
mysqldump -uroot -pjt jira2|gzip >/var/backup/ft_jobs_jira2_`date +%Y%m%d`.dump.gz
find /var/backup/ -mtime +30 -exec rm -f {} \;



Ce script doit être lancé à chaque démarrage de votre session.