Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
d6d9fbf6e4
|
|||
ffbf8ece91
|
|||
6c07c147ae
|
|||
5ddd374350
|
14
README.md
14
README.md
@ -20,6 +20,10 @@ The script uses rsync to actually run the backup, so you will have to install it
|
||||
sudo pacman -Syu rsync
|
||||
```
|
||||
|
||||
It's also required to have python-dotenv
|
||||
|
||||
Optional dependencies are systemd-python to enable using systemd journal for logging, and dbus-python for desktop notifications.
|
||||
|
||||
## Install
|
||||
To install the program, first clone the repository:
|
||||
|
||||
@ -27,23 +31,21 @@ To install the program, first clone the repository:
|
||||
git clone https://github.com/Fuxino/simple_backup.git
|
||||
```
|
||||
|
||||
Install tools required to build and install the package:
|
||||
Then install the tools required to build the package:
|
||||
|
||||
```bash
|
||||
pip install --upgrade build installer wheel
|
||||
pip install --upgrade build wheel
|
||||
```
|
||||
|
||||
Then run:
|
||||
Finally, run:
|
||||
|
||||
```bash
|
||||
cd simple_backup
|
||||
python -m build --wheel
|
||||
python -m installer dist/*.whl
|
||||
python -m pip install dist/*.whl
|
||||
```
|
||||
|
||||
For Arch Linux and Arch-based distros, two packages are available in the AUR (aur.archlinux.org):
|
||||
- **simple_backup** for the release version
|
||||
- **simple_backup-git** for the git version
|
||||
|
||||
After installing, copy simple_backup.conf (if you used the PKGBUILD on Arch, it will be in /etc/simple_backup/) to $HOME/.config/simple_backup and edit is as needed.
|
||||
|
||||
|
@ -56,6 +56,9 @@ Same as rsync option \(aq\-\-checksum\(aq, use checksums instead of mod\-time an
|
||||
.B \-\-remove\-before\-backup
|
||||
Remove old backups (if necessary) before creating the new backup. Useful to free some space before performing the backup.
|
||||
Default behavior is to remove old backups after successfully completing the backup.
|
||||
.TP
|
||||
.B \-\-no\-syslog
|
||||
Don't use systemd journal for logging
|
||||
.SH CONFIGURATION
|
||||
An example configuration file is provided at \(aq/etc/simple_backup/simple_backup.conf\(aq. Copy it to the default location
|
||||
($HOME/.config/simple_backup) and edit it as needed.
|
||||
|
@ -25,7 +25,12 @@ packages = simple_backup
|
||||
python_requires = >=3.7
|
||||
install_requires =
|
||||
python-dotenv
|
||||
|
||||
[options.extras_require]
|
||||
JOURNAL =
|
||||
systemd-python
|
||||
NOTIFICATIONS =
|
||||
dbus-python
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
|
@ -1,8 +0,0 @@
|
||||
post_install() {
|
||||
echo "An example configuration file is found in /etc/simple_backup/simple_backup.conf."
|
||||
echo "Copy it to ~/config/simple_backup/simple_backup.conf and modify it as needed"
|
||||
}
|
||||
|
||||
post_upgrade() {
|
||||
post_install
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
"""Init."""
|
||||
|
||||
__version__ = '3.2.7'
|
||||
__version__ = '3.3.0'
|
||||
|
@ -125,9 +125,6 @@ class Backup:
|
||||
except FileNotFoundError:
|
||||
return
|
||||
|
||||
if dirs.count('last_backup') > 0:
|
||||
dirs.remove('last_backup')
|
||||
|
||||
n_backup = len(dirs) - 1
|
||||
count = 0
|
||||
|
||||
@ -150,14 +147,16 @@ class Backup:
|
||||
logger.info(f'Removed {count} backups')
|
||||
|
||||
def find_last_backup(self):
|
||||
if os.path.islink(f'{self.output}/simple_backup/last_backup'):
|
||||
link = os.readlink(f'{self.output}/simple_backup/last_backup')
|
||||
|
||||
if os.path.isdir(link):
|
||||
self._last_backup = link
|
||||
else:
|
||||
try:
|
||||
dirs = sorted([f.path for f in os.scandir(f'{self.output}/simple_backup') if f.is_dir(follow_symlinks=False)])
|
||||
except FileNotFoundError:
|
||||
logger.info('No previous backups available')
|
||||
else:
|
||||
|
||||
return
|
||||
|
||||
try:
|
||||
self._last_backup = dirs[-1]
|
||||
except IndexError:
|
||||
logger.info('No previous backups available')
|
||||
|
||||
# Function to read configuration file
|
||||
@ -170,8 +169,8 @@ class Backup:
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
self.create_backup_dir()
|
||||
self.find_last_backup()
|
||||
self.create_backup_dir()
|
||||
|
||||
_, self._inputs_path = mkstemp(prefix='tmp_inputs', text=True)
|
||||
_, self._exclude_path = mkstemp(prefix='tmp_exclude', text=True)
|
||||
@ -215,25 +214,6 @@ class Backup:
|
||||
logger.info(f'rsync: {output[-3]}')
|
||||
logger.info(f'rsync: {output[-2]}')
|
||||
|
||||
if os.path.islink(f'{self.output}/simple_backup/last_backup'):
|
||||
try:
|
||||
os.remove(f'{self.output}/simple_backup/last_backup')
|
||||
except FileNotFoundError:
|
||||
logger.error('Failed to remove last_backup link. File not found')
|
||||
self._err_flag = True
|
||||
except PermissionError:
|
||||
logger.error('Failed to remove last_backup link. Permission denied')
|
||||
self._err_flag = True
|
||||
|
||||
try:
|
||||
os.symlink(self._output_dir, f'{self.output}/simple_backup/last_backup', target_is_directory=True)
|
||||
except FileExistsError:
|
||||
logger.error('Failed to create last_backup link. Link already exists')
|
||||
self._err_flag = True
|
||||
except PermissionError:
|
||||
logger.error('Failed to create last_backup link. Permission denied')
|
||||
self._err_flag = True
|
||||
|
||||
if self.keep != -1 and not self.remove_before:
|
||||
self.remove_old_backups()
|
||||
|
||||
@ -250,7 +230,10 @@ class Backup:
|
||||
except NameError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
notify('Backup finished')
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
|
||||
def _parse_arguments():
|
||||
@ -269,6 +252,7 @@ def _parse_arguments():
|
||||
help='Use checksum rsync option to compare files (MUCH SLOWER)')
|
||||
parser.add_argument('--remove-before-backup', action='store_true',
|
||||
help='Remove old backups before executing the backup, instead of after')
|
||||
parser.add_argument('--no-syslog', action='store_true', help='Disable systemd journal logging')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -314,6 +298,13 @@ def notify(text):
|
||||
|
||||
def simple_backup():
|
||||
args = _parse_arguments()
|
||||
|
||||
if args.no_syslog:
|
||||
try:
|
||||
logger.removeHandler(j_handler)
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
inputs, output, exclude, keep = _read_config(args.config)
|
||||
|
||||
if args.input is not None:
|
||||
|
Reference in New Issue
Block a user