Dưới là đoạn shell scrip backup svn, mình đã thực hiện thành công, nhưng mình muốn khi backup nó tự động tao ra 1 thư mục của ngày hôm đó (VD: 16-04-2013) và lưu dữ liệu backup vào trong thư mục đó, mong thầy và anh em giúp đỡ.
#!/bin/bash
bakdate=$(date +%Y%m%d%H%M)
echo "--------------------------------"
echo "Running SVN backup $bakdate"
echo "--------------------------------\n"
# From where to backup repos?
# ---------------------------
svnrepos="/var/svn"
echo "\nGoing to backup all SVN repos located at: $svnrepos \n"
# Where to save the dump?
# ------------------------
bakdest="/root/backup_svn/svn"
MAKE=`mkdir $bakdest/$bakdate`
$MAKE
# Location for USB drive? (to copy backup)
# ----------------------------------------
baktousb="/media/USB/Extra-BACKUP"
# _________NO-COFIG-REQUIRED-BELOW-THIS-LINE___________
# First go to SVN repo folder
cd $svnrepos
# Just make sure we have write access to backup-folder
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
# Now $repo has folder names = project names
for repo in *; do
# do svn dump for each project
echo "Taking backup/svndump for: $repo"
echo "Executing : svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump \n"
# Now finally execute the backup
svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump
# You can go an extra mile by applying tar-gz compression to svn-dumps
# We also would like to save the dump to remote place/usb
if [ -d "$baktousb" ] && [ -w "$baktousb" ] ; then
# USB/other directory exists, copy the dump there
echo "Going to copy $repo dump to $baktousb directory...\n"
cp $bakdest/$repo-$bakdate.svn.dump $baktousb
fi
done
else
echo "Unable to continue SVN backup process."
echo "$bakdest is *NOT* a directory or you do not have write permission."
fi
# End of backup script
echo "\n\n================================="
echo " - Backup Complete, THANK YOU :-]"
#!/bin/bash
bakdate=$(date +%Y%m%d%H%M)
echo "--------------------------------"
echo "Running SVN backup $bakdate"
echo "--------------------------------\n"
# From where to backup repos?
# ---------------------------
svnrepos="/var/svn"
echo "\nGoing to backup all SVN repos located at: $svnrepos \n"
# Where to save the dump?
# ------------------------
bakdest="/root/backup_svn/svn"
MAKE=`mkdir $bakdest/$bakdate`
$MAKE
# Location for USB drive? (to copy backup)
# ----------------------------------------
baktousb="/media/USB/Extra-BACKUP"
# _________NO-COFIG-REQUIRED-BELOW-THIS-LINE___________
# First go to SVN repo folder
cd $svnrepos
# Just make sure we have write access to backup-folder
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
# Now $repo has folder names = project names
for repo in *; do
# do svn dump for each project
echo "Taking backup/svndump for: $repo"
echo "Executing : svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump \n"
# Now finally execute the backup
svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump
# You can go an extra mile by applying tar-gz compression to svn-dumps
# We also would like to save the dump to remote place/usb
if [ -d "$baktousb" ] && [ -w "$baktousb" ] ; then
# USB/other directory exists, copy the dump there
echo "Going to copy $repo dump to $baktousb directory...\n"
cp $bakdest/$repo-$bakdate.svn.dump $baktousb
fi
done
else
echo "Unable to continue SVN backup process."
echo "$bakdest is *NOT* a directory or you do not have write permission."
fi
# End of backup script
echo "\n\n================================="
echo " - Backup Complete, THANK YOU :-]"
Comment