Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
labsync-tray
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto LIVIO BECCARIA
labsync-tray
Commits
c00c0e2a
Commit
c00c0e2a
authored
7 months ago
by
Alberto LIVIO BECCARIA
Browse files
Options
Downloads
Patches
Plain Diff
Nuovo script di backup
parent
14792bf9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backup.sh
+111
-6
111 additions, 6 deletions
backup.sh
with
111 additions
and
6 deletions
backup.sh
+
111
−
6
View file @
c00c0e2a
#!/bin/bash
#!/usr/bin/env bash
##########
# CONFIG ###############################################################
########################################################################
BACKUP_PATH
=
~/pCloudDrive/
EXCLUDE
=(
'.git'
'public'
'node_modules'
'venv'
)
##########
# FUNCTIONS ############################################################
########################################################################
ANAME
=
${
PWD
##*/
}
ANAME
=
${
PWD
##*/
}
T
=
`
date
+
"%Y-%m-%d_%H%M"
`
T
=
`
date
+
"%Y-%m-%d_%H%M"
`
FILENAME
=
${
ANAME
}
_
${
T
}
FILENAME
=
${
ANAME
}
_
${
T
}
echo
"Linux "
$T
>
version.txt
# https://askubuntu.com/a/1386907
#tar cvzf ../${FILENAME}.tgz ../${ANAME}/
function
choose_from_menu
()
{
rar a
-r
-m5
../
${
FILENAME
}
.rar ../
${
ANAME
}
/
-x
../
${
ANAME
}
/node_modules
local
prompt
=
"
$1
"
outvar
=
"
$2
"
#rar a -r -m5 ../${FILENAME}.rar ../${ANAME}/
shift
read
-p
"Ok"
shift
local
options
=(
"
$@
"
)
cur
=
0
count
=
${#
options
[@]
}
index
=
0
local
esc
=
$(
echo
-en
"
\e
"
)
# cache ESC as test doesn't allow esc codes
printf
"
$prompt
\n
"
while
true
do
# list all options (option list is zero-based)
index
=
0
for
o
in
"
${
options
[@]
}
"
do
if
[
"
$index
"
==
"
$cur
"
]
then
echo
-e
" >
\e
[7m
$o
\e
[0m"
# mark & highlight the current option
else
echo
"
$o
"
fi
index
=
$((
$index
+
1
))
done
read
-s
-n3
key
# wait for user to key in arrows or ENTER
if
[[
$key
==
$esc
[
A
]]
# up arrow
then
cur
=
$((
$cur
-
1
))
[
"
$cur
"
-lt
0
]
&&
cur
=
0
elif
[[
$key
==
$esc
[
B
]]
# down arrow
then
cur
=
$((
$cur
+
1
))
[
"
$cur
"
-ge
$count
]
&&
cur
=
$((
$count
-
1
))
elif
[[
$key
==
""
]]
# nothing, i.e the read delimiter - ENTER
then
break
fi
echo
-en
"
\e
[
${
count
}
A"
# go up to the beginning to re-render
done
# export the selection to the requested output variable
printf
-v
$outvar
"
${
options
[
$cur
]
}
"
}
##########
# MAIN #################################################################
########################################################################
#echo "Linux "$T > version.txt
selections
=(
"TAR + 7ZIP"
"TAR + GZIP"
"RAR"
"7ZIP"
)
choose_from_menu
"Tipo archivio:"
selected_choice
"
${
selections
[@]
}
"
echo
"Archivio selezionato:
$selected_choice
"
echo
echo
"EXCLUDE:
${
EXCLUDE
[@]
}
"
echo
read
-p
"Premi un tasto per continuare o CTRL-C per interrompere"
case
$selected_choice
in
"TAR + 7ZIP"
)
FILENAME+
=
".tar.7z"
exclude_options
=()
for
x
in
"
${
EXCLUDE
[@]
}
"
;
do
exclude_options+
=(
--exclude
=
"
$x
"
)
done
tar
"
${
exclude_options
[@]
}
"
-cvf
- ../
"
${
ANAME
}
"
/ | 7z a
-si
../
"
${
FILENAME
}
"
;;
"TAR + GZIP"
)
FILENAME+
=
".tgz"
exclude_options
=()
for
x
in
"
${
EXCLUDE
[@]
}
"
;
do
exclude_options+
=(
--exclude
=
"
$x
"
)
done
tar
"
${
exclude_options
[@]
}
"
-cvzf
../
"
${
FILENAME
}
"
../
"
${
ANAME
}
"
;;
"RAR"
)
FILENAME+
=
".rar"
exclude_options
=()
for
x
in
"
${
EXCLUDE
[@]
}
"
;
do
exclude_options+
=(
-x
"../
${
ANAME
}
/
$x
"
)
done
rar a
-r
-m5
../
"
${
FILENAME
}
"
../
"
${
ANAME
}
"
/
"
${
exclude_options
[@]
}
"
;;
"7ZIP"
)
FILENAME+
=
".7z"
exclude_options
=()
for
x
in
"
${
EXCLUDE
[@]
}
"
;
do
exclude_options+
=(
-x
"!
${
ANAME
}
/
$x
"
)
done
7z a
"
${
exclude_options
[@]
}
"
../
"
${
FILENAME
}
"
../
"
${
ANAME
}
"
/
;;
esac
echo
read
-p
"Sposta su disco di backup? (s/n)? "
answer
case
${
answer
:0:1
}
in
s|S
)
mv
../
${
FILENAME
}
${
BACKUP_PATH
}
;;
*
)
;;
esac
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment