syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.68k stars 4.89k forks source link

Backups #8947

Closed GregorySchwartz closed 2 months ago

GregorySchwartz commented 7 years ago

I somehow had half of a document deleted and looked for the backups with autosave. However, there is a discrete difference in autosave verses backups. I was curious as to why there were no backups being generated and found #2271. I don't think this is a solution to the backups problem by disabling it completely -- I had to re-enable it and come up with my own configurations to save backups per session ~/.backups/per-session and per save ~/.backups/per-save. Can we have a nice interface for this in spacemacs?

Gathered from around the web, probably all from https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files#151946:

  ;; Backups
  (setq make-backup-files t)
  (setq version-control t     ;; Use version numbers for backups.
        kept-new-versions 10  ;; Number of newest versions to keep.
        kept-old-versions 0   ;; Number of oldest versions to keep.
        delete-old-versions t ;; Don't ask to delete excess backup versions.
        backup-by-copying t)  ;; Copy all files, don't rename them.
  (setq vc-make-backup-files t)
  ;; Default and per-save backups go here:
  (setq backup-directory-alist '(("" . "~/.backup/per-save")))

  (defun force-backup-of-buffer ()
    ;; Make a special "per session" backup at the first save of each
    ;; emacs session.
    (when (not buffer-backed-up)
      ;; Override the default parameters for per-session backups.
      (let ((backup-directory-alist '(("" . "~/.backup/per-session")))
            (kept-new-versions 3))
        (backup-buffer)))
    ;; Make a "per save" backup on each save.  The first save results in
    ;; both a per-session and a per-save backup, to keep the numbering
    ;; of per-save backups consistent.
    (let ((buffer-backed-up nil))
      (backup-buffer)))

  (add-hook 'before-save-hook  'force-backup-of-buffer)
svenpanne commented 7 years ago

As an Emacs user for decades who recently switched to spacemacs, I'm slightly confused: Why is the following in config.el at all?

;; don't create backup~ files
(setq make-backup-files nil)

2271 mentions that there is a rationale for this, but what is it? What can I do to get the traditional way back, e.g. only 1 non-numbered backup living directly next to the original file? Googling around didn't show anything useful. Has setting back make-backup-files to t any negative effect?

Having at least one backup of the previous state is essential for an editor IMHO, not every file is under version control.

jwnki commented 6 years ago

I absolutely agree with @svenpanne Why use such a bad default at all? I just lost a file which I couldn't recover from auto-save, and was really upset with this no backup policy. Especially, since usually the defaults in spacemacs are set in a smart way.

jeffmacdonald commented 6 years ago

Here here. I'd love to know more context/history about this one.

hyiltiz commented 5 years ago

As #2271 pointed out, Spacemacs does save backups for local and remote edits under ~/.emacs.d/.cache/auto-save/site. Before you freak out, it may be practical to first check if your file still has a backup there.

igor-kupczynski commented 5 years ago

As #2271 pointed out, Spacemacs does save backups for local and remote edits under ~/.emacs.d/.cache/auto-save/site. Before you freak out, it may be practical to first check if your file still has a backup there.

@hyiltiz these are not backups, but rather autosaves. See http://pragmaticemacs.com/emacs/auto-save-and-backup-every-save/ :

Emacs has two useful ways of protecting you from data loss. The first is auto save, which saves a copy of a file every so often while you are editing it. If some catastrophe caused you to close Emacs or shut down your machine without saving the file then you can use M-x recover-file to recover the file from its auto save. (...) The other way Emacs protects you is to make backups of your files. By default the backup file is made in the same directory as the original with a name like file~. The way the backup works is that Emacs makes a copy of a file the first time you save it in an Emacs session.

Spacemacs does auto saves, but not backups

@GregorySchwartz provided a nice descriptions on how backups could be configured in spacemacs and I've coded something like that in a layer https://github.com/syl20bnr/spacemacs/pull/11903

hyiltiz commented 5 years ago

As mentioned in #2271, this line in the snipped above (setq make-backup-files t) is crucial it is not mentioned in StackOverflow, EmacsWiki or most others' setup on Emac's backup functionality as it was on by default in vanilla Emacs. Any other backup configurations will not kick in without it.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

GregorySchwartz commented 4 years ago

I believe this feature is still very much needed.

hyiltiz commented 4 years ago

@GregorySchwartz could you propose what needs to be done by Spacemacs to resolve then close it?

svenpanne commented 4 years ago

@GregorySchwartz could you propose what needs to be done by Spacemacs to resolve then close it?

I think people (including me) simply want the traditional Emacs behavior back, i.e. keeping (perhaps numbered) backups of files which are not under version control. I think almost nobody understands in detail why this isn't the case with Spacemacs or how to fix that, because nobody really understands the rationale for disabling it. :thinking:

GregorySchwartz commented 4 years ago

@hyiltiz I currently use my solution in the original post, but it looks like @igor-kupczynski submitted a pull request for their own layer in https://github.com/syl20bnr/spacemacs/pull/11903.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

ColeWunderlich commented 3 years ago

I believe this is valuable behaviour and do not understand why it is disabled. (I just spent a good 15 min trying to figure out why I couldn't find any backup files until I eventually found this issue).

If for some reason spacemacs is against creating backups in the local directory, they could be stored by default in a similar location to autosaves, ie ~/.emacs.d/.cache/backups

This could be enabled in the default config with something along the lines of:

(setq make-backup-files t)
(setq backup-directory-alist `(("." . "~/.emacs.d/.cache/backups")))
github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!