Backup + Upload + Delete

Skye

Member
Jul 18, 2015
24
5
35
Hello I was wondering if someone could create a linux script which zips a certain thing and than uploads to an off site server.
 

Supervisor

Administrator
Apr 27, 2015
1,863
2,546
335
fuck.. thats still on my todo list.. :(
I hope I will be able to do it tomorrow... because I actually have something like that setup already :)

please tag me with "@Supervisor" tomorrow again so I dont forget xD
 

Ramadi

Member
Mar 12, 2016
79
19
43
1- zip : tar -zcvf FileName.tar.gz FolderName
2- transfer : scp -P 22 /Path/to/FileName.tar.gz 185.185.185.185:/Path/
3- delete : rm -rf FileOrFolderName
 

MrKek

Member
Mar 15, 2016
56
51
56
Why are you not using a Script like theses for OVH FTP Backup, its pretty the same.

Code:
#!/bin/bash
#
# Backing up the OVH server, checking the archive and sending it through FTP
#

# Copyright © 2013 Carl Chenet <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

BACKUPHOME=/home/backups
FTPUSER=ftpbackupser
FTPPASS=S0m3Th1nGH4rD
FTPSERVER=ftp.server.com
SERVER=youservername
MYSQLUSER=backup
MYSQLPASS=S0m4Th1nGTr1cKy
PKGLIST=$BACKUPHOME/installed-packages
DBDUMP=$BACKUPHOME/mysqldumpall.sql
ARCHIVE=$BACKUPHOME/$SERVER-backup-`date +%d-%m-%Y`.tar.bz2
[email protected]

# create BACKUPHOME if not exists
mkdir -p $BACKUPHOME
# get installed Debian packages
dpkg --get-selections| awk -F' ' '{print $1}' > $PKGLIST
if [ $RETVAL != 0 ];then   
    echo "Issue while using dpkg --get-selections of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# get mysql database
mysqldump -u$MYSQLUSER -p$MYSQLPASS --all-databases > $DBDUMP
if [ $RETVAL != 0 ];then   
    echo "Issue while performing mysqldump of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# get directories and files
tar --preserve-permissions --preserve-order -j -c -f $ARCHIVE /etc /var /home /opt /usr/local/bin $DBDUMP \
    --exclude=/var/lib/mysql/data \
    --exclude=$BACKUPHOME/$SERVER-backup* \
    --exclude=/var/cache/apt/archives > /dev/null 2>&1
# remove one-month-old archive on the FTP
lftp -e "rm -f $SERVER-backup-`date -d "-10 day" +%d-%m-%Y`.tar.bz2;exit" -u $FTPUSER,$FTPPASS $FTPSERVER > /dev/null 2>&1
if [ $RETVAL != 0 ];then   
    echo "Issue while removing the old archive of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# send the archive to ftp account
lftp -e "mput $ARCHIVE;exit" -u $FTPUSER,$FTPPASS $FTPSERVER > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL != 0 ];then   
    echo "Issue while uploading the archive from $SERVER to $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# remove the local backups
rm -f $PKGLIST $DBDUMP $ARCHIVE
exit 0
 

Skye

Member
Jul 18, 2015
24
5
35
Why are you not using a Script like theses for OVH FTP Backup, its pretty the same.

Code:
#!/bin/bash
#
# Backing up the OVH server, checking the archive and sending it through FTP
#

# Copyright © 2013 Carl Chenet <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

BACKUPHOME=/home/backups
FTPUSER=ftpbackupser
FTPPASS=S0m3Th1nGH4rD
FTPSERVER=ftp.server.com
SERVER=youservername
MYSQLUSER=backup
MYSQLPASS=S0m4Th1nGTr1cKy
PKGLIST=$BACKUPHOME/installed-packages
DBDUMP=$BACKUPHOME/mysqldumpall.sql
ARCHIVE=$BACKUPHOME/$SERVER-backup-`date +%d-%m-%Y`.tar.bz2
[email protected]

# create BACKUPHOME if not exists
mkdir -p $BACKUPHOME
# get installed Debian packages
dpkg --get-selections| awk -F' ' '{print $1}' > $PKGLIST
if [ $RETVAL != 0 ];then  
    echo "Issue while using dpkg --get-selections of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# get mysql database
mysqldump -u$MYSQLUSER -p$MYSQLPASS --all-databases > $DBDUMP
if [ $RETVAL != 0 ];then  
    echo "Issue while performing mysqldump of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# get directories and files
tar --preserve-permissions --preserve-order -j -c -f $ARCHIVE /etc /var /home /opt /usr/local/bin $DBDUMP \
    --exclude=/var/lib/mysql/data \
    --exclude=$BACKUPHOME/$SERVER-backup* \
    --exclude=/var/cache/apt/archives > /dev/null 2>&1
# remove one-month-old archive on the FTP
lftp -e "rm -f $SERVER-backup-`date -d "-10 day" +%d-%m-%Y`.tar.bz2;exit" -u $FTPUSER,$FTPPASS $FTPSERVER > /dev/null 2>&1
if [ $RETVAL != 0 ];then  
    echo "Issue while removing the old archive of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# send the archive to ftp account
lftp -e "mput $ARCHIVE;exit" -u $FTPUSER,$FTPPASS $FTPSERVER > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL != 0 ];then  
    echo "Issue while uploading the archive from $SERVER to $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
fi
# remove the local backups
rm -f $PKGLIST $DBDUMP $ARCHIVE
exit 0

How does this work?
 

MrKek

Member
Mar 15, 2016
56
51
56
How does this work?
Default you are using this Script for the OVH Backup FTP. But its nothing else like a FTP Server. You enter every Parameter and execute this Script with a Cronjob.
Here you can change the Folders to Backup
Code:
tar --preserve-permissions --preserve-order -j -c -f $ARCHIVE /etc /var /home /opt /usr/local/bin $DBDUMP \

Anyway, if you have problem with this Script. Search on Google for a FTP Backup Script or eg. OVH FTP Backup Script. There are some good one.
 
Top