Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Config
Commits
fe50e4b4
Commit
fe50e4b4
authored
May 08, 2016
by
Igor Pecovnik
Browse files
rework #1
parent
eb82e894
Changes
2
Hide whitespace changes
Inline
Side-by-side
backup and restore/backup.sh
View file @
fe50e4b4
...
...
@@ -11,84 +11,80 @@ COPY_FROM=/var/www/clients
USER
=
PASSWORD
=
HOST
=
localhost
#
mkdir
-p
$COPY_TO
echo
""
;
echo
"************************************"
;
echo
" CRONTAB BACKUP"
;
echo
"************************************"
;
echo
""
;
crontab
-l
>
$COPY_TO
/crontab-root.txt
echo
""
;
echo
"************************************"
;
echo
" DATABASES BACKUP"
;
echo
"************************************"
;
echo
""
;
for
db
in
$(
echo
'SHOW DATABASES;'
|mysql
-u
$USER
-p
$PASSWORD
-h
$HOST
|grep
-v
'^Database$'
|grep
-v
"^performance_schema"
|grep
-v
"^information_schema"
|grep
-v
"^mysql"
)
;
do
mysqldump
\
function
crontab_backup
()
{
echo
-e
"[
\e
[0;32m o.k.
\x
1B[0m]
\e
[1;32m
$1
\x
1B[0mCrontab backup"
crontab
-l
>
$COPY_TO
/crontab-root.txt
}
function
database_backup
()
{
for
db
in
$(
echo
'SHOW DATABASES;'
|mysql
-u
$USER
-p
$PASSWORD
-h
$HOST
|grep
-v
'^Database$'
|grep
-v
"^performance_schema"
|grep
-v
"^information_schema"
|grep
-v
"^mysql"
)
;
do
mysqldump
\
-u
$USER
-p
$PASSWORD
-h
$HOST
\
-Q
-c
-C
--add-drop-table
--add-locks
--quick
--lock-tables
\
$db
|
gzip
--best
-c
>
$COPY_TO
/
$DBBACKUPNAME
-
$db
.sql.gz
;
echo
"Backup of"
$db
;
done
;
echo
""
;
echo
"************************************"
;
echo
" WEB BACKUP"
;
echo
"************************************"
;
echo
""
;
echo
"Wait a moment please..."
;
for
x
in
$(
find
$COPY_FROM
-maxdepth
2
-name
"web*"
-type
d
-print0
| xargs
-0
)
do
tar
-cpvzf
$COPY_TO
/
$WEBBACKUPNAME
-
$(
basename
$x
)
.tar.gz
$x
&> /dev/null
done
;
echo
""
;
echo
"************************************"
;
echo
" CONF BACKUP"
;
echo
"************************************"
;
echo
""
;
service dovecot stop
service cups stop
service transmission-daemon stop
service hostapd stop
service postfix stop
service tvheadend stop
service samba stop
/etc/init.d/scanbuttond stop
/etc/init.d/vpnserver stop
# backup only minimum
tar
cvPfz
$COPY_TO
/
$FILEBACKUPNAME
-allfiles
.tgz
-T
filelist.txt
--exclude
=
'*.sock'
echo
""
;
echo
"************************************"
;
echo
" MAIL BACKUP"
;
echo
"************************************"
;
echo
""
;
#
tar
cvPfz
$COPY_TO
/
$FILEBACKUPNAME
-mail
.tgz /var/vmail
#
service dovecot start
service cups start
service transmission-daemon start
service hostapd start
service postfix start
service tvheadend start
service samba start
/etc/init.d/scanbuttond start
/etc/init.d/vpnserver start
echo
""
;
echo
"************************************"
;
echo
" INSTALLED PACKAGE LIST BACKUP"
;
echo
"************************************"
;
echo
""
;
aptitude search
'~i !~M !~pstandard !~pimportant !~prequired'
|
awk
'{print $2}'
>
$COPY_TO
/installedpackages
echo
-e
"[
\e
[0;32m o.k.
\x
1B[0m]
\e
[1;32m
$1
\x
1B[0mDatabase
$db
backup"
done
;
}
function
web_backup
()
{
echo
-e
"[
\e
[0;32m o.k.
\x
1B[0m]
\e
[1;32m
$1
\x
1B[0mWebsites backup"
for
x
in
$(
find
$COPY_FROM
-maxdepth
2
-name
"web*"
-type
d
-print0
| xargs
-0
)
do
tar
-cpvzf
$COPY_TO
/
$WEBBACKUPNAME
-
$(
basename
$x
)
.tar.gz
$x
&> /dev/null
done
;
}
function
conf_backup
()
{
/etc/init.d/scanbuttond stop
/etc/init.d/vpnserver stop
service transmission-daemon stop
service tvheadend stop
service cups stop
service samba stop
echo
-e
"[
\e
[0;32m o.k.
\x
1B[0m]
\e
[1;32m
$1
\x
1B[0mConf files backup"
tar
cvPfz
$COPY_TO
/
$FILEBACKUPNAME
-allfiles
.tgz
-T
filelist.txt
--exclude
=
'*.sock'
service samba start
service cups start
service tvheadend start
service transmission-daemon start
/etc/init.d/scanbuttond start
/etc/init.d/vpnserver start
}
function
mail_backup
()
{
service dovecot stop
service postfix stop
echo
-e
"[
\e
[0;32m o.k.
\x
1B[0m]
\e
[1;32m
$1
\x
1B[0mMail backup"
tar
cvPfz
$COPY_TO
/
$FILEBACKUPNAME
-mail
.tgz /var/vmail
service postfix start
service dovecot start
}
function
pkglist_backup
()
{
echo
-e
"[
\e
[0;32m o.k.
\x
1B[0m]
\e
[1;32m
$1
\x
1B[0mPackage list backup"
aptitude search
'~i !~M !~pstandard !~pimportant !~prequired'
|
awk
'{print $2}'
>
$COPY_TO
/installedpackages
}
# main app
crontab_backup
database_backup
web_backup
conf_backup
mail_backup
pkglist_backup
\ No newline at end of file
backup and restore/filelist.txt
View file @
fe50e4b4
...
...
@@ -19,6 +19,7 @@
/usr/local/bin/.sync
/etc/mysql/my.cnf
/etc/default/stunnel4
/usr/local/vpnserver/vpn_server.config
/usr/bin/tv_grab_file
/home/hts/.hts/tvheadend
/etc/samba/smb.conf
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment